:root {
  --primary-color: #3E2723; /* Dark Wood */
  --secondary-color: #4A5D23; /* Moss Green */
  --bg-color: #F2EFE9; /* Ivory / Paper */
  --text-main: #2C3E50; /* Ink Black */
  --text-light: #5c6d7e;
  --white: #F9F6F0; /* Off-white / old paper */
  --success: #4A5D23;
  --error: #8B0000; /* Dull Red */
  --accent-mustard: #D4AF37;
  --border-radius: 8px; /* Soft edges */
  --box-shadow: 2px 4px 10px rgba(62, 39, 35, 0.15);
  
  --font-heading: "Shippori Mincho", "Yu Mincho", "Noto Serif JP", serif;
  --font-body: "Shippori Mincho", "Yu Mincho", "Noto Serif JP", serif;
  --font-en: "Courier Prime", "Special Elite", monospace;

  /* Animations */
  --transition-speed: 0.4s;
}

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

.fade-in {
  animation: fadeIn var(--transition-speed) ease-out forwards;
}

.loading-overlay {
  opacity: 0;
  transition: opacity var(--transition-speed);
}

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

html, body {
  max-width: 100vw;
  overflow-x: hidden;
  margin: 0;
  padding: 0;
}

body {
  font-family: var(--font-body);
  background-color: var(--bg-color);
  color: var(--text-main);
  line-height: 2.0;
  background-image: url('data:image/svg+xml,%3Csvg viewBox="0 0 200 200" xmlns="http://www.w3.org/2000/svg"%3E%3Cfilter id="noiseFilter"%3E%3CfeTurbulence type="fractalNoise" baseFrequency="0.65" numOctaves="3" stitchTiles="stitch"/%3E%3C/filter%3E%3Crect width="100%25" height="100%25" filter="url(%23noiseFilter)" opacity="0.05"/%3E%3C/svg%3E');
  overflow-wrap: break-word;
  word-break: break-word;
}

/* Header - Unified Cafe Style */
.app-header {
  background-color: #FAF9F6;
  color: var(--primary-color);
  padding: 0;
  border-bottom: 2px solid #E8E2D8;
  position: sticky;
  top: 0;
  z-index: 1100;
  box-shadow: 0 4px 20px rgba(62, 39, 35, 0.08);
}

.header-container {
  width: 100%;
  max-width: 100%;
  margin: 0;
  padding: 0 1.5rem;
  display: flex;
  justify-content: space-between;
  align-items: stretch;
  height: 80px;
}

#app-title {
  font-family: var(--font-heading);
  font-size: 2.2rem;
  font-weight: 900;
  cursor: pointer;
  display: flex;
  align-items: center;
  gap: 12px;
  color: var(--primary-color);
  text-shadow: 1px 1px 0px rgba(212, 175, 55, 0.3);
  transition: transform 0.3s cubic-bezier(0.175, 0.885, 0.32, 1.275);
}
#app-title:hover {
  transform: scale(1.02);
}
#app-title::before {
  content: '☕';
  font-size: 1.8rem;
}

#nav-controls {
  display: flex;
  align-items: center;
  gap: 0;
  height: 100%;
  flex: 1;
  margin-left: 1rem;
}

.user-greeting {
  font-size: 1rem;
  color: #000 !important; /* Force black text */
  background: #FFFFFF;
  border: 1.5px solid #3E2723; /* Dark border for definition */
  border-radius: 20px;
  margin-right: 1.5rem;
  font-weight: 800;
  padding: 0.4rem 1.5rem;
  height: 40px;
  display: flex;
  align-items: center;
  box-shadow: 0 2px 5px rgba(0,0,0,0.1);
  white-space: nowrap;
}

.btn-text {
  background: transparent;
  border: none;
  color: var(--primary-color);
  cursor: pointer;
  font-family: var(--font-heading);
  font-size: 0.95rem;
  font-weight: bold;
  padding: 0 1rem;
  height: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.3s;
  position: relative;
  border-radius: 0;
  flex: 1; /* Expand to fill width */
  white-space: nowrap;
}

.btn-text:hover {
  background: rgba(62, 39, 35, 0.05);
  color: var(--secondary-color);
}

.btn-text::after {
  content: '';
  position: absolute;
  bottom: 0;
  left: 10%;
  width: 80%;
  height: 4px;
  background: var(--accent-mustard);
  transform: scaleX(0);
  transition: transform 0.3s;
  border-radius: 2px 2px 0 0;
}

.btn-text:hover::after {
  transform: scaleX(1);
}

/* Wide Button Accent */
.btn-text.active {
  color: var(--secondary-color);
}
.btn-text.active::after {
  transform: scaleX(1);
}

/* Main Layout with Dual Sidebars */
.app-layout {
  width: 100%;
  max-width: 100%;
  margin: 0;
  padding: 1.5rem;
  min-height: calc(100vh - 80px);
}

.main-container {
  display: flex;
  gap: 1.5rem;
  align-items: flex-start;
  width: 100%;
}

#app-content {
  flex: 1;
  min-width: 0;
  background: var(--white);
  border-radius: 12px;
  box-shadow: var(--box-shadow);
  padding: 2rem;
  transition: opacity var(--transition-speed);
}

.app-sidebar {
  width: 240px;
  flex-shrink: 0;
  position: sticky;
  top: 95px;
}

.sidebar-left { order: 1; }
#app-content { order: 2; }
.sidebar-right { order: 3; }

/* Removed redundant media queries, moved to the bottom for consolidated control */

.sidebar-ad-placeholder {
  background: #FDFBF8;
  border: 1px dashed #D8D0C0;
  border-radius: 8px;
  padding: 1rem;
  text-align: center;
}

.sidebar-ad-placeholder p {
  font-size: 0.65rem;
  color: #B0A890;
  margin-bottom: 0.5rem;
  letter-spacing: 0.1em;
  font-weight: bold;
}

.ad-box {
  width: 100%;
  aspect-ratio: 1 / 1;
  background: #E8E2D8;
  margin-top: 0.5rem;
  border-radius: 4px;
  display: flex;
  align-items: center;
  justify-content: center;
  position: relative;
  overflow: hidden;
}

.ad-box::after {
  content: 'AD SPACE';
  font-size: 0.8rem;
  font-weight: bold;
  color: #FFF;
  opacity: 0.5;
}

/* Removed redundant media query */

#app-content.loading {
  opacity: 0;
}

/* Search Bar in Header */
#search-container, #user-search-container {
  display: flex;
  align-items: center;
  background: #EEE9DE;
  border-radius: 30px;
  padding: 4px 12px;
  border: 1px solid #D8D0C0;
  transition: all 0.3s;
  width: 220px;
  margin: 0 0.5rem;
}
#search-container:focus-within, #user-search-container:focus-within {
  background: #FFF;
  box-shadow: 0 0 0 3px rgba(212, 175, 55, 0.2);
  width: 260px;
}
#search-input, #user-search-input {
  background: transparent;
  border: none;
  outline: none;
  padding: 8px;
  font-family: var(--font-heading);
  font-size: 0.85rem;
  width: 100%;
  color: var(--primary-color);
}
#search-btn, #user-search-btn {
  background: none;
  border: none;
  cursor: pointer;
  font-size: 1rem;
  color: var(--primary-color);
  padding: 0 8px;
  transition: transform 0.2s;
}
#search-btn:hover, #user-search-btn:hover {
  transform: scale(1.2);
}

/* Home Page */
.page-title {
  text-align: center;
  color: var(--primary-color);
  margin-bottom: 2rem;
  font-size: 2rem;
}

.subject-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(250px, 1fr));
  gap: 1.5rem;
}

.subject-card {
  background: var(--white);
  border-radius: var(--border-radius);
  padding: 2rem;
  text-align: center;
  cursor: pointer;
  box-shadow: var(--box-shadow);
  transition: transform 0.2s, box-shadow 0.2s;
  border-bottom: 4px solid var(--secondary-color);
}

.subject-card:hover {
  transform: translateY(-5px);
  box-shadow: 0 8px 12px rgba(0,0,0,0.1);
}

.subject-card h2 {
  color: var(--primary-color);
  font-size: 1.5rem;
}

/* Subject/Genre Page */
.genre-list {
  display: flex;
  flex-direction: column;
  gap: 1.5rem;
  max-width: 800px;
  margin: 0 auto;
}

.genre-card {
  background: var(--white);
  border-radius: var(--border-radius);
  padding: 1.5rem;
  box-shadow: var(--box-shadow);
}

.genre-title {
  font-size: 1.3rem;
  color: var(--primary-color);
  border-bottom: 2px solid var(--bg-color);
  padding-bottom: 0.5rem;
  margin-bottom: 1rem;
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.article-list {
  list-style: none;
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}

.article-item {
  padding: 1rem;
  border-radius: var(--border-radius);
  cursor: pointer;
  transition: background 0.2s;
  display: flex;
  justify-content: space-between;
  align-items: center;
  border: 1px solid var(--bg-color);
}

.article-item:hover {
  background-color: #E8F0F2;
  border-color: var(--secondary-color);
}

.article-title {
  font-weight: 500;
}

/* Badge */
.badge-done {
  background-color: var(--success);
  color: white;
  padding: 0.2rem 0.6rem;
  border-radius: 12px;
  font-size: 0.8rem;
  font-weight: bold;
}

/* Study Page */
.study-container {
  display: flex;
  gap: 2rem;
  align-items: flex-start;
}

@media (max-width: 768px) {
  .study-container {
    flex-direction: column;
  }
}

.article-content {
  flex: 3;
  background: var(--white);
  padding: 4rem;
  border-radius: var(--border-radius);
  box-shadow: var(--box-shadow);
  line-height: 2.2; /* Better readability */
  max-width: 850px;
  margin: 0 auto;
  position: relative;
  overflow: hidden;
}

.article-content::before {
  content: '';
  position: absolute;
  top: 0; left: 0; right: 0; height: 6px;
  background: linear-gradient(to right, var(--primary-color), var(--accent-mustard), var(--secondary-color));
}

.article-content h1 {
  color: var(--primary-color);
  margin-bottom: 0.5rem;
  border: none;
  font-size: 2.4rem;
  letter-spacing: -0.5px;
  text-align: center;
}

.article-meta {
  display: flex;
  justify-content: center;
  gap: 15px;
  font-size: 0.9rem;
  color: var(--text-light);
  margin-bottom: 3rem;
  font-family: var(--font-en);
}

.article-meta .meta-item {
  display: flex;
  align-items: center;
  gap: 5px;
}

.article-content h2 {
  color: var(--primary-color);
  margin-top: 3.5rem;
  margin-bottom: 1.5rem;
  font-size: 1.6rem;
  border-bottom: 1px solid #E8E2D8;
  padding-bottom: 0.5rem;
  position: relative;
}

.article-content h2::after {
  content: '';
  position: absolute;
  bottom: -1px; left: 0; width: 60px;
  height: 3px; background: var(--accent-mustard);
}

.article-content p {
  margin-bottom: 2rem;
  font-size: 1.15rem;
  text-align: justify;
}

/* Removed Magazine-style Drop Cap */

.study-block {
  margin-bottom: 2.5rem;
}

/* Quiz UI */
.quiz-section {
  flex: 2;
  background: var(--white);
  padding: 2rem;
  border-radius: var(--border-radius);
  box-shadow: var(--box-shadow);
  position: sticky;
  top: 90px;
}

.quiz-question {
  font-size: 1.1rem;
  font-weight: bold;
  margin-bottom: 1.5rem;
  color: var(--text-main);
  line-height: 1.5;
}

.quiz-choices {
  display: flex;
  flex-direction: column;
  gap: 0.8rem;
}

.choice-btn {
  background-color: var(--white);
  border: 2px solid var(--bg-color);
  padding: 1rem;
  border-radius: var(--border-radius);
  font-size: 1rem;
  cursor: pointer;
  text-align: left;
  transition: all 0.2s;
  font-family: inherit;
  color: var(--text-main);
}

.choice-btn:hover:not(:disabled) {
  background-color: #E8F0F2;
  border-color: var(--secondary-color);
}

.choice-btn:disabled {
  cursor: default;
}

.choice-btn.correct {
  background-color: #E8F5E9;
  border-color: var(--success);
  color: var(--success);
  font-weight: bold;
}

.choice-btn.wrong {
  background-color: #FFEBEE;
  border-color: var(--error);
  color: var(--error);
}

.quiz-result {
  margin-top: 1.5rem;
  padding: 1.5rem;
  border-radius: var(--border-radius);
  display: none;
  animation: fadeIn 0.5s ease;
}

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

.result-correct {
  background-color: #E8F5E9;
  border: 1px solid var(--success);
}

.result-wrong {
  background-color: #FFEBEE;
  border: 1px solid var(--error);
}

.result-title {
  font-size: 1.2rem;
  font-weight: bold;
  margin-bottom: 0.8rem;
}

.result-correct .result-title { color: var(--success); }
.result-wrong .result-title { color: var(--error); }

.explanation {
  font-size: 0.95rem;
  color: var(--text-main);
  line-height: 1.6;
  background: rgba(255,255,255,0.7);
  padding: 1rem;
  border-radius: 4px;
}

.btn-next {
  margin-top: 1.5rem;
  background-color: var(--primary-color);
  color: var(--white);
  border: none;
  padding: 1rem;
  border-radius: var(--border-radius);
  font-size: 1rem;
  cursor: pointer;
  width: 100%;
  font-family: inherit;
  font-weight: bold;
  transition: background-color 0.2s;
}

.btn-next:hover {
  background-color: var(--secondary-color);
}

/* Internal Quiz (Inline) Styles */
.quiz-reveal-wrap {
  margin: 2rem 0;
  border: 1.5px solid var(--primary-color);
  border-radius: var(--border-radius);
  overflow: hidden;
  background: var(--white);
  box-shadow: var(--box-shadow);
}

.quiz-challenge-btn {
  width: 100%;
  padding: 1.2rem;
  background: var(--white);
  border: none;
  border-bottom: 1px solid var(--bg-color);
  font-family: var(--font-heading);
  font-size: 1.1rem;
  color: var(--primary-color);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  transition: all 0.3s;
}

.quiz-challenge-btn:hover {
  background: #f9f4eb;
  letter-spacing: 1px;
}

.quiz-challenge-btn span {
  font-size: 1.4rem;
  transition: transform 0.4s cubic-bezier(0.175, 0.885, 0.32, 1.275);
}

.quiz-challenge-btn.is-open span {
  transform: rotate(180deg) scale(1.2);
}

.quiz-reveal-body {
  padding: 2rem;
  background-image: linear-gradient(to bottom, #fffcf8, #fdfaf4);
  animation: slideDown 0.4s ease-out;
}

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

/* Editor Specific Internal Quiz UI */
.ne-internal-quiz-wrap {
  margin: 1rem 0;
}

.ne-iq-card {
  border: 1px solid var(--primary-color);
  border-radius: var(--border-radius);
  background: #fff;
  overflow: hidden;
}

.ne-iq-header {
  background: var(--primary-color);
  color: var(--white);
  padding: 0.5rem 1rem;
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-size: 0.9rem;
}

.ne-iq-remove-blk {
  background: none;
  border: none;
  color: var(--white);
  cursor: pointer;
  font-size: 1rem;
  opacity: 0.6;
  transition: opacity 0.2s;
}

.ne-iq-remove-blk:hover { opacity: 1; }

.ne-iq-body {
  padding: 1rem;
  display: flex;
  flex-direction: column;
  gap: 1rem;
}

.ne-iq-input {
  width: 100%;
  padding: 0.6rem;
  border: 1px solid var(--bg-color);
  border-radius: 4px;
  font-family: inherit;
  font-size: 1rem;
}

.ne-iq-input.q {
  font-weight: bold;
  border-left: 4px solid var(--accent-mustard);
}

.ne-iq-opt-row {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 0.5rem;
}

.ne-iq-add-opt {
  align-self: flex-start;
  font-size: 0.85rem;
  color: var(--secondary-color);
  background: none;
  border: 1px dashed var(--secondary-color);
  padding: 0.3rem 0.8rem;
  border-radius: 4px;
  cursor: pointer;
}

.ne-iq-add-opt:hover {
  background: #f0f4f0;
}

.ne-iq-opt-del {
  background: none;
  border: none;
  color: var(--error);
  cursor: pointer;
  font-size: 0.9rem;
  opacity: 0.5;
  transition: opacity 0.2s;
}

.ne-iq-opt-del:hover { opacity: 1; }

.ne-iq-input.expl {
  font-size: 0.9rem;
  color: var(--text-light);
  border-style: dotted;
}

/* Toolbar Submenus */
.ne-tb-group {
  position: relative;
  display: flex;
}

.ne-tb-submenu {
  position: absolute;
  bottom: 100%;
  left: 0;
  background: var(--primary-color);
  border-radius: 6px;
  display: flex;
  flex-direction: column;
  padding: 5px;
  box-shadow: 0 -4px 12px rgba(0,0,0,0.2);
  margin-bottom: 8px;
  min-width: 80px;
}

.ne-tb-subitem {
  padding: 5px 10px;
  color: white;
  cursor: pointer;
  font-size: 0.85rem;
  border-radius: 4px;
  white-space: nowrap;
}

.ne-tb-subitem:hover {
  background: rgba(255,255,255,0.2);
}

/* Text Size Variations */
.sz-sm { font-size: 0.85rem; }
.sz-md { font-size: 1rem; }
.sz-lg { font-size: 1.5rem; font-weight: bold; }
.sz-xl { font-size: 2.2rem; font-weight: 900; line-height: 1.2; }

/* Premium Gradients */
.gr-gold {
  background: linear-gradient(to right, #BF953F, #FCF6BA, #B38728, #FBF5B7, #AA771C);
  -webkit-background-clip: text;
  background-clip: text;
  -webkit-text-fill-color: transparent;
  display: inline-block;
}

.gr-sunset {
  background: linear-gradient(45deg, #ff512f, #dd2476);
  -webkit-background-clip: text;
  background-clip: text;
  -webkit-text-fill-color: transparent;
  display: inline-block;
}

.gr-forest {
  background: linear-gradient(to right, #11998e, #38ef7d);
  -webkit-background-clip: text;
  background-clip: text;
  -webkit-text-fill-color: transparent;
  display: inline-block;
}

.gr-espresso {
  background: linear-gradient(to right, #2c3e50, #4ca1af);
  -webkit-background-clip: text;
  background-clip: text;
  -webkit-text-fill-color: transparent;
  display: inline-block;
}

.gr-jazz {
  background: linear-gradient(135deg, #833ab4, #fd1d1d, #fcb045);
  -webkit-background-clip: text;
  background-clip: text;
  -webkit-text-fill-color: transparent;
  display: inline-block;
}

/* Login Page */
.login-wrapper {
  display: flex;
  justify-content: center;
  align-items: center;
  min-height: 60vh;
}

.login-card {
  background: var(--white);
  padding: 2.5rem;
  border-radius: var(--border-radius);
  box-shadow: var(--box-shadow);
  width: 100%;
  max-width: 400px;
}

/* Terms of Service Styles */
.tos-group {
  margin-top: 1rem;
  margin-bottom: 1.5rem;
  display: flex;
  align-items: flex-start;
  gap: 10px;
  font-size: 0.9rem;
  color: var(--text-main);
  background: rgba(0,0,0,0.03);
  padding: 10px;
  border-radius: 4px;
}

.tos-group input {
  margin-top: 4px;
  cursor: pointer;
}

.tos-link {
  color: var(--primary-color);
  text-decoration: underline;
  cursor: pointer;
  font-weight: bold;
}

.tos-modal {
  position: fixed;
  top: 0; left: 0; width: 100%; height: 100%;
  background: rgba(0,0,0,0.5);
  display: none;
  justify-content: center;
  align-items: center;
  z-index: 1000;
  backdrop-filter: blur(4px);
}

.tos-content {
  background: var(--white);
  width: 90%;
  max-width: 500px;
  max-height: 70vh;
  padding: 2rem;
  border-radius: var(--border-radius);
  box-shadow: 0 10px 30px rgba(0,0,0,0.3);
  overflow-y: auto;
  position: relative;
  font-family: var(--font-body);
}

.tos-content h4 {
  color: var(--primary-color);
  margin-bottom: 1rem;
  border-bottom: 2px solid var(--secondary-color);
  padding-bottom: 0.5rem;
}

.tos-close-btn {
  display: block;
  width: 100%;
  margin-top: 1.5rem;
  padding: 10px;
  background: var(--primary-color);
  color: white;
  border: none;
  border-radius: 4px;
  cursor: pointer;
  font-weight: bold;
}

.login-logo {
  text-align: center;
  color: var(--primary-color);
  font-size: 1.3rem;
  margin-bottom: 2rem;
  border-bottom: 2px solid var(--secondary-color);
  padding-bottom: 1rem;
}

#form-title {
  text-align: center;
  margin-bottom: 1.5rem;
  color: var(--text-main);
}

.form-group {
  margin-bottom: 1.5rem;
}

.form-group label {
  display: block;
  margin-bottom: 0.5rem;
  font-weight: 500;
}

.form-group input {
  width: 100%;
  padding: 0.8rem;
  border: 1px solid #ccc;
  border-radius: 4px;
  font-size: 1rem;
  font-family: inherit;
}

.form-group input:focus {
  outline: none;
  border-color: var(--primary-color);
  box-shadow: 0 0 0 2px rgba(26, 95, 122, 0.2);
}

.password-input-wrapper {
  position: relative;
  display: flex;
  align-items: center;
}

.password-input-wrapper input {
  padding-right: 45px !important;
}

.password-toggle {
  position: absolute;
  right: 12px;
  background: none;
  border: none;
  cursor: pointer;
  font-size: 1.2rem;
  padding: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--text-light);
  transition: transform 0.2s, opacity 0.2s;
  user-select: none;
  z-index: 5;
}

.password-toggle:hover {
  opacity: 0.7;
  transform: scale(1.1);
}

.password-toggle:active {
  transform: scale(0.9);
}

.btn-primary {
  width: 100%;
  padding: 1rem;
  background-color: var(--primary-color);
  color: var(--white);
  border: none;
  border-radius: var(--border-radius);
  font-size: 1.1rem;
  font-weight: bold;
  cursor: pointer;
  transition: background-color 0.2s;
}

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

.toggle-form {
  text-align: center;
  margin-top: 1.5rem;
}

.btn-text-dark {
  background: none;
  border: none;
  color: var(--primary-color);
  cursor: pointer;
  font-weight: 500;
  text-decoration: underline;
  font-size: 0.95rem;
}

.error-message {
  background-color: #FFEBEE;
  color: var(--error);
  padding: 0.8rem;
  border-radius: 4px;
  margin-bottom: 1.5rem;
  font-size: 0.9rem;
  border: 1px solid var(--error);
}

.success-message {
  background-color: #E8F5E9;
  color: var(--success);
  padding: 0.8rem;
  border-radius: 4px;
  margin-bottom: 1.5rem;
  font-size: 0.9rem;
  border: 1px solid var(--success);
}

.user-greeting {
  color: var(--white);
  margin-right: 1.5rem;
  font-weight: bold;
}

#nav-controls {
  display: flex;
  align-items: center;
  gap: 1rem;
}

/* Progress Bar */
.progress-container {
  width: 100%;
  background-color: #E0E0E0;
  border-radius: 10px;
  margin-top: 1rem;
  overflow: hidden;
  height: 12px;
  position: relative;
}

.progress-fill {
  height: 100%;
  background-color: var(--secondary-color);
  width: 0%;
  border-radius: 10px;
  transition: width 1s ease-in-out;
}

.progress-text {
  font-size: 0.85rem;
  color: var(--text-light);
  margin-top: 0.5rem;
  text-align: right;
  font-weight: bold;
}

/* Profile Page */
.profile-wrapper {
  max-width: 800px;
  margin: 0 auto;
  background: var(--white);
  padding: 3rem;
  border-radius: var(--border-radius);
  box-shadow: var(--box-shadow);
}

.profile-header {
  display: flex;
  align-items: center;
  gap: 2rem;
  margin-bottom: 3rem;
  flex-wrap: wrap;
}

.profile-avatar {
  width: 150px;
  height: 150px;
  border-radius: 50%;
  object-fit: cover;
  border: 4px solid #FF9800; /* Accent Color */
}

.profile-info h1 {
  margin: 0;
  font-size: 2rem;
  color: var(--primary-color);
}

.profile-info .subtitle {
  font-size: 1.1rem;
  color: #FF9800;
  font-weight: bold;
  margin-bottom: 1rem;
}

.profile-info p {
  line-height: 1.6;
  color: var(--text-main);
}

.profile-section {
  margin-bottom: 3rem;
}

.profile-section h2 {
  color: var(--primary-color);
  border-bottom: 2px solid #FF9800;
  padding-bottom: 0.5rem;
  margin-bottom: 1.5rem;
}

.story-text {
  line-height: 1.8;
  font-size: 1.05rem;
}

.skill-item {
  margin-bottom: 1.5rem;
}

.skill-name {
  display: flex;
  justify-content: space-between;
  font-weight: bold;
  margin-bottom: 0.5rem;
}

.skill-bar-container {
  width: 100%;
  background-color: #E0E0E0;
  height: 16px;
  border-radius: 8px;
  overflow: hidden;
}

.skill-bar-fill {
  height: 100%;
  background-color: #FF9800;
  width: 0%;
  border-radius: 8px;
  transition: width 1.5s ease-out;
}

/* SVOC Reading Styles */
.svoc-sentence {
  cursor: pointer;
  padding: 0.5rem;
  border-radius: 4px;
  transition: background-color 0.2s;
  font-size: 1.1rem;
  line-height: 1.6;
}
.svoc-sentence:hover {
  background-color: #f0f7ff;
}
.svoc-details {
  background-color: #fafafa;
  border-left: 4px solid var(--primary-color);
  padding: 1rem;
  margin-top: 0.5rem;
  margin-bottom: 1.5rem;
  border-radius: 0 4px 4px 0;
  display: none;
  animation: fadeIn 0.3s ease;
}
.svoc-details.active {
  display: block;
}
.svoc-ja {
  font-weight: bold;
  margin-bottom: 0.5rem;
  color: var(--text-main);
}
.svoc-box {
  display: inline-block;
  margin-right: 0.5rem;
  margin-bottom: 0.5rem;
  padding: 0.3rem 0.6rem;
  border-radius: 4px;
  font-size: 0.9rem;
  font-weight: bold;
  color: #fff;
}
.svoc-S { background-color: #e53935; }
.svoc-V { background-color: #1e88e5; }
.svoc-O { background-color: #43a047; }
.svoc-C { background-color: #8e24aa; }
.svoc-M { background-color: #757575; }

/* Flashcard Styles */
.flashcard-container {
  perspective: 1000px;
  width: 100%;
  max-width: 400px;
  height: 250px;
  margin: 2rem auto;
  position: relative;
}
.flashcard {
  width: 100%;
  height: 100%;
  position: relative;
  transition: transform 0.6s, opacity 0.3s, left 0.3s;
  transform-style: preserve-3d;
  cursor: pointer;
}
.flashcard.flipped {
  transform: rotateY(180deg);
}
.flashcard-front, .flashcard-back {
  position: absolute;
  width: 100%;
  height: 100%;
  backface-visibility: hidden;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 12px;
  box-shadow: 0 4px 10px rgba(0,0,0,0.15);
  font-size: 1.8rem;
  font-weight: bold;
  padding: 1rem;
  text-align: center;
}
.flashcard-front {
  background-color: var(--white);
  color: var(--primary-color);
}
.flashcard-back {
  background-color: var(--primary-color);
  color: var(--white);
  transform: rotateY(180deg);
}
.flashcard-controls {
  display: flex;
  justify-content: center;
  gap: 1rem;
  margin-top: 1.5rem;
}

/* Ordering Quiz Styles */
.ordering-container {
  margin-top: 1rem;
}
.ordering-dropzone {
  min-height: 60px;
  border: 2px dashed #ccc;
  border-radius: 8px;
  padding: 10px;
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  margin-bottom: 1.5rem;
  background-color: #f9f9f9;
}
.ordering-choices {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  margin-bottom: 1.5rem;
}
.ordering-word {
  background-color: var(--white);
  border: 1px solid var(--primary-color);
  color: var(--primary-color);
  padding: 0.5rem 1rem;
  border-radius: 20px;
  cursor: pointer;
  font-weight: bold;
  user-select: none;
  transition: all 0.2s;
}
.ordering-word:hover {
  background-color: var(--primary-color);
  color: #fff;
}

/* Countdown Timer */
.countdown-container {
  background: linear-gradient(135deg, #1A5F7A, #2293B0);
  color: white;
  padding: 1.5rem;
  border-radius: var(--border-radius);
  text-align: center;
  margin-bottom: 2rem;
  box-shadow: 0 8px 15px rgba(0,0,0,0.1);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
}
.countdown-text {
  font-size: 1.2rem;
  margin-bottom: 0.5rem;
}
.countdown-number {
  font-size: 3rem;
  font-weight: bold;
  line-height: 1;
  text-shadow: 2px 2px 4px rgba(0,0,0,0.2);
}
.countdown-input-group {
  margin-top: 1rem;
  display: flex;
  gap: 0.5rem;
}
.countdown-input-group input {
  padding: 0.5rem;
  border: none;
  border-radius: 4px;
  color: #333;
}
.countdown-input-group button {
  background-color: #FF9800;
  color: white;
  border: none;
  padding: 0.5rem 1rem;
  border-radius: 4px;
  cursor: pointer;
  font-weight: bold;
}

/* Review List */
.review-list-container {
  margin-bottom: 2rem;
}
.review-section-title {
  color: #E65100;
  font-size: 1.3rem;
  margin-bottom: 1rem;
  display: flex;
  align-items: center;
  gap: 0.5rem;
}
.review-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
  gap: 1rem;
}
.review-card {
  background: white;
  border-left: 4px solid #FF9800;
  padding: 1rem;
  border-radius: var(--border-radius);
  box-shadow: var(--box-shadow);
  cursor: pointer;
  transition: transform 0.2s;
}
.review-card:hover {
  transform: translateY(-3px);
}
.review-card-title {
  font-weight: bold;
  color: var(--primary-color);
  margin-bottom: 0.5rem;
}
.review-card-timing {
  font-size: 0.85rem;
  color: #666;
  background: #FFF3E0;
  padding: 0.2rem 0.5rem;
  border-radius: 12px;
  display: inline-block;
}

/* Learning Calendar */
.calendar-container {
  background: white;
  padding: 1.5rem;
  border-radius: var(--border-radius);
  box-shadow: var(--box-shadow);
  margin-bottom: 2rem;
}
.calendar-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 1rem;
  color: var(--primary-color);
  font-weight: bold;
  font-size: 1.2rem;
}
.calendar-grid {
  display: grid;
  grid-template-columns: repeat(7, 1fr);
  gap: 5px;
  text-align: center;
}
.calendar-day-header {
  font-size: 0.85rem;
  font-weight: bold;
  color: #888;
  padding: 0.5rem 0;
}
.calendar-day {
  aspect-ratio: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 50%;
  font-size: 0.9rem;
  position: relative;
  background-color: #f9f9f9;
}
.calendar-day.studied {
  background-color: #E8F5E9;
  color: var(--success);
  font-weight: bold;
  border: 2px solid var(--success);
}
.calendar-day.studied::after {
  content: '済';
  position: absolute;
  top: -5px;
  right: -5px;
  background: #FF9800;
  color: white;
  font-size: 0.6rem;
  padding: 2px 4px;
  border-radius: 8px;
}
.calendar-day.empty {
  background-color: transparent;
}

/* Ranking Timeline */
.ranking-container {
  background: white;
  padding: 1.5rem;
  border-radius: var(--border-radius);
  box-shadow: var(--box-shadow);
  margin-bottom: 2rem;
}
.ranking-title {
  color: var(--primary-color);
  font-size: 1.2rem;
  margin-bottom: 1rem;
  display: flex;
  align-items: center;
  gap: 0.5rem;
}
.ranking-list {
  display: flex;
  flex-direction: column;
  gap: 0.8rem;
}
.ranking-item {
  display: flex;
  align-items: center;
  padding: 0.8rem;
  background: #f9f9f9;
  border-radius: 8px;
}
.ranking-rank {
  font-size: 1.2rem;
  font-weight: bold;
  color: #888;
  width: 30px;
  text-align: center;
  margin-right: 1rem;
}
.ranking-item:nth-child(1) .ranking-rank { color: #FFD700; font-size: 1.5rem; }
.ranking-item:nth-child(2) .ranking-rank { color: #C0C0C0; font-size: 1.4rem; }
.ranking-item:nth-child(3) .ranking-rank { color: #CD7F32; font-size: 1.3rem; }
.ranking-user {
  flex-grow: 1;
  font-weight: bold;
}
.ranking-score {
  background: var(--primary-color);
  color: white;
  padding: 0.2rem 0.6rem;
  border-radius: 12px;
  font-size: 0.85rem;
}

/* Editor Interactive Styles */
.reveal-text {
  background-color: #d1d5db;
  color: transparent;
  padding: 2px 6px;
  border-radius: 4px;
  cursor: pointer;
  transition: all 0.3s ease;
  user-select: none;
}
.reveal-text.is-revealed {
  background-color: #fff3cd;
  color: #333;
  border: 1px solid #ffeeba;
}

/* ---------------------------------
   Interactive Elements (Retro Cafe)
--------------------------------- */
.advanced-reveal {
  position: relative;
  display: inline-block;
  padding: 2px 8px;
  border-radius: var(--border-radius);
  cursor: pointer;
  perspective: 1000px;
  transform-style: preserve-3d;
  font-family: var(--font-heading);
  box-shadow: var(--box-shadow);
  margin: 0 4px;
}

/* 隠蔽状態（古い本のカバー風） */
.advanced-reveal.state-masked {
  background-color: var(--primary-color);
  color: var(--accent-mustard);
  border: 1px solid #2a1a17;
  font-weight: bold;
  letter-spacing: 2px;
}

/* ヒント状態 */
.advanced-reveal.state-hint {
  background-color: #fcf1b6;
  color: var(--error);
  border: 1px dashed var(--accent-mustard);
}

/* 正解表示状態（紙がめくれるアニメーション） */
.advanced-reveal.state-revealed {
  background-color: #fff9e6;
  color: var(--text-main);
  border: 1px solid #d4c5b0;
  animation: pageFlip 0.6s cubic-bezier(0.4, 0.0, 0.2, 1) forwards;
}

@keyframes pageFlip {
  0% { transform: rotateX(90deg) scale(0.9); opacity: 0.5; }
  50% { transform: rotateX(-10deg) scale(1.05); }
  100% { transform: rotateX(0deg) scale(1); opacity: 1; }
}

/* 色鉛筆風の傍線 */
.comment-trigger {
  position: relative;
  font-weight: bold;
  cursor: pointer;
  background-image: linear-gradient(
    to right,
    rgba(139, 0, 0, 0) 0%,
    rgba(139, 0, 0, 0.8) 10%,
    rgba(139, 0, 0, 0.6) 50%,
    rgba(139, 0, 0, 0.9) 80%,
    rgba(139, 0, 0, 0) 100%
  );
  background-position: bottom 2px center;
  background-size: 100% 3px;
  background-repeat: no-repeat;
  padding-bottom: 2px;
  color: var(--text-main);
}
.comment-trigger:hover {
  color: var(--error);
}

/* 付箋風の捲り機能 (物理的なはがれるアニメーション) */
.sticky-note-reveal {
  position: relative;
  display: inline-block;
  cursor: pointer;
  padding: 0 6px;
  margin: 0 2px;
  font-weight: bold;
  border-radius: 4px;
  user-select: none;
  transition: color 0.3s ease, background-color 0.3s ease;
  line-height: 1.3;
  vertical-align: middle;
}

/* 粘着時（答えが隠れている状態）：背景色と文字色を同じにして完璧に隠蔽 */
.sticky-note-reveal:not(.is-revealed) {
  background-color: #ffeb3b !important;
  color: #ffeb3b !important;
  text-shadow: none !important;
}

/* 付箋本体のリアルな外観 */
.sticky-note-reveal::after {
  content: "";
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: linear-gradient(135deg, #FFF59D 0%, #FFEE58 100%);
  border-left: 3px solid #FBC02D; /* 粘着部分の表現 */
  border-radius: 3px;
  box-shadow: 2px 3px 6px rgba(0, 0, 0, 0.15);
  transform-origin: top center;
  transition: transform 0.4s cubic-bezier(0.23, 1, 0.32, 1), opacity 0.35s ease, box-shadow 0.35s ease;
  pointer-events: none; /* 親のクリックイベントを通す */
  z-index: 10;
}

/* ホバー時の少し浮き上がるエフェクト */
.sticky-note-reveal:not(.is-revealed):hover::after {
  transform: translateY(-2px) scaleY(1.05);
  box-shadow: 3px 5px 10px rgba(0, 0, 0, 0.2);
}

/* 付箋がはがれた（めくられた）状態 */
.sticky-note-reveal.is-revealed {
  color: #3E2723 !important; /* 暗褐色の文字を露出 */
  background-color: rgba(255, 235, 59, 0.15) !important; /* めくった後はマーカー風のハイライト */
}

.sticky-note-reveal.is-revealed::after {
  transform: translateY(-12px) rotate(6deg) scale(0.95);
  opacity: 0 !important;
  box-shadow: none;
}
/* 古びた付箋風ツールチップ */
.tooltip-panel {
  display: none;
  position: absolute;
  background-color: #fcf1b6;
  color: #333;
  padding: 12px 16px;
  border-radius: 2px 8px 8px 8px;
  box-shadow: 2px 4px 8px rgba(0,0,0,0.2);
  font-family: var(--font-body);
  border: 1px solid #e0d08b;
  z-index: 1000;
  width: max-content;
  max-width: 300px;
  top: calc(100% + 8px);
  left: 50%;
  transform: translateX(-50%);
  filter: sepia(0.2);
}

.comment-trigger.is-active .tooltip-panel {
  display: block;
  animation: stickNote 0.3s ease-out forwards;
}

@keyframes stickNote {
  from { opacity: 0; transform: translateX(-50%) translateY(10px) rotate(-2deg); }
  to { opacity: 1; transform: translateX(-50%) translateY(0) rotate(0deg); }
}

/* ---------------------------------
   Antique Nested Box
--------------------------------- */
.nested-box {
  background-color: rgba(255, 255, 255, 0.4);
  padding: 1.5rem;
  margin: 1.5rem 0;
  border-radius: var(--border-radius);
  border: 3px double var(--accent-mustard);
  box-shadow: inset 0 0 20px rgba(212, 175, 55, 0.1);
  position: relative;
}

.nested-box::before {
  content: "✤";
  position: absolute;
  top: -12px;
  left: 50%;
  transform: translateX(-50%);
  background-color: var(--bg-color);
  padding: 0 10px;
  color: var(--accent-mustard);
  font-size: 1.2rem;
}

/* ── Team Ranking (Home) ─────────────────────── */
.team-ranking-container {
  margin-top: 2rem;
  background: var(--white);
  border-radius: var(--border-radius);
  padding: 1.5rem;
  box-shadow: var(--box-shadow);
}
.team-ranking-title {
  font-size: 1.1rem;
  font-weight: bold;
  color: var(--primary-color);
  font-family: 'Shippori Mincho', serif;
  margin-bottom: 1rem;
  padding-bottom: 0.5rem;
  border-bottom: 1px solid var(--bg-color);
}
.team-ranking-list { display: flex; flex-direction: column; gap: 10px; }
.team-rank-row {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 14px;
  background: var(--bg-color);
  border-radius: 6px;
  border-left: 4px solid #D8D0C0;
}
.team-rank-medal { font-size: 1.3rem; flex-shrink: 0; }
.team-rank-icon  { font-size: 1.3rem; flex-shrink: 0; }
.team-rank-name  { font-weight: bold; flex-shrink: 0; }
.team-rank-stats { font-size: 0.8rem; color: var(--text-light); flex: 1; }
.team-rank-score { font-size: 1.4rem; font-weight: bold; color: var(--secondary-color); flex-shrink: 0; }

/* ── Fun Tools Section (BMI + Cookie Clicker) ───────────────────── */

/* 2カラムのグリッドレイアウト */
.fun-tools-grid {
  display: grid;
  grid-template-columns: 1fr 1fr; /* 左右2列に並べる */
  gap: 1.5rem;
  margin-top: 1rem;
}

/* スマホの場合は1列に変える */
@media (max-width: 640px) {
  .fun-tools-grid {
    grid-template-columns: 1fr;
  }
}

/* 各ツールのカード */
.fun-card {
  background: var(--bg-color);
  border: 2px solid var(--accent-mustard);
  border-radius: var(--border-radius);
  padding: 1.5rem;
  display: flex;
  flex-direction: column;
  gap: 0.8rem;
}

.fun-card-title {
  font-size: 1.15rem;
  font-weight: bold;
  color: var(--primary-color);
  padding-bottom: 0.5rem;
  border-bottom: 1px dashed var(--accent-mustard);
}

.fun-card-desc {
  font-size: 0.9rem;
  color: var(--text-light);
}

/* ── BMI フォーム ── */
.fun-form-row {
  display: flex;
  gap: 1rem;
}

.fun-input-group {
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 0.3rem;
}

.fun-input-group label {
  font-size: 0.85rem;
  font-weight: bold;
  color: var(--text-main);
}

.fun-input-wrap {
  display: flex;
  align-items: center;
  gap: 0.4rem;
}

.fun-input-wrap input {
  width: 100%;
  padding: 0.5rem 0.7rem;
  border: 1px solid #ccc;
  border-radius: 4px;
  font-size: 1rem;
  font-family: inherit;
  background: var(--white);
}

.fun-input-wrap input:focus {
  outline: none;
  border-color: var(--primary-color);
  box-shadow: 0 0 0 2px rgba(62, 39, 35, 0.15);
}

.fun-unit {
  font-size: 0.85rem;
  color: var(--text-light);
  white-space: nowrap;
}

/* メインのボタン */
.fun-btn {
  background-color: var(--primary-color);
  color: var(--white);
  border: none;
  border-radius: var(--border-radius);
  padding: 0.6rem 1.2rem;
  font-size: 0.95rem;
  font-family: inherit;
  font-weight: bold;
  cursor: pointer;
  transition: background-color 0.2s, transform 0.1s;
  align-self: flex-start;
}

.fun-btn:hover {
  background-color: var(--secondary-color);
  transform: translateY(-1px);
}

/* サブボタン（リセット用） */
.fun-btn-secondary {
  background: none;
  border: 2px solid var(--primary-color);
  border-radius: var(--border-radius);
  color: var(--primary-color);
  padding: 0.4rem 1rem;
  font-size: 0.85rem;
  font-family: inherit;
  font-weight: bold;
  cursor: pointer;
  transition: all 0.2s;
  align-self: flex-start;
  margin-top: 0.5rem;
}

.fun-btn-secondary:hover {
  background-color: var(--primary-color);
  color: var(--white);
}

/* ── BMI 結果ボックス ── */
.bmi-result-box {
  border-radius: var(--border-radius);
  padding: 1rem 1.2rem;
  font-size: 0.95rem;
  animation: fadeIn 0.4s ease;
}

/* 各判定の色 */
.bmi-thin    { background: #E3F2FD; border-left: 4px solid #42A5F5; color: #1565C0; }
.bmi-normal  { background: #E8F5E9; border-left: 4px solid #66BB6A; color: #2E7D32; }
.bmi-over1   { background: #FFF8E1; border-left: 4px solid #FFCA28; color: #F57F17; }
.bmi-over2   { background: #FFEBEE; border-left: 4px solid #EF5350; color: #B71C1C; }
.bmi-result-error { background: #FFF3E0; border-left: 4px solid #FF9800; color: #E65100; }

.bmi-value {
  font-size: 1.4rem;
  font-weight: bold;
  margin-bottom: 0.3rem;
}

.bmi-label {
  font-size: 1rem;
  margin-bottom: 0.3rem;
}

.bmi-note {
  font-size: 0.78rem;
  opacity: 0.75;
  margin-top: 0.2rem;
}

/* ── クッキークリッカー ── */
.cookie-game-area {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.6rem;
  padding: 0.5rem 0;
}

/* クッキーボタン本体 */
.cookie-btn {
  font-size: 3.5rem;
  background: none;
  border: none;
  cursor: pointer;
  line-height: 1;
  transition: transform 0.1s;
  user-select: none;
  /* タッチデバイスで押したときのハイライトをなくす */
  -webkit-tap-highlight-color: transparent;
}

.cookie-btn:hover {
  transform: scale(1.1);
}

/* クリック時のポップアニメーション */
@keyframes cookiePop {
  0%   { transform: scale(1); }
  40%  { transform: scale(1.35) rotate(-8deg); }
  70%  { transform: scale(0.9)  rotate(4deg);  }
  100% { transform: scale(1)   rotate(0deg);  }
}

.cookie-btn.cookie-pop {
  animation: cookiePop 0.3s ease-out forwards;
}

/* スコア表示エリア */
.cookie-score-wrap {
  display: flex;
  flex-direction: column;
  align-items: center;
}

.cookie-score-label {
  font-size: 0.8rem;
  color: var(--text-light);
  text-transform: uppercase;
  letter-spacing: 1px;
}

.cookie-score-num {
  font-size: 2.5rem;
  font-weight: bold;
  color: var(--primary-color);
  line-height: 1.1;
  font-family: var(--font-en);
}

/* ランクメッセージ */
.cookie-rank-msg {
  font-size: 0.95rem;
  color: var(--secondary-color);
  font-weight: bold;
  min-height: 1.4em;
}


/* Password Reset & Messages */
.error-message, .success-message, .info-message {
  padding: 1rem;
  border-radius: var(--border-radius);
  margin-bottom: 1.5rem;
  font-size: 0.95rem;
  text-align: center;
  animation: fadeIn 0.3s ease;
  line-height: 1.5;
}

.error-message { background: #FFEBEE; color: var(--error); border: 1px solid #FFCDD2; }
.success-message { background: #E8F5E9; color: var(--success); border: 1px solid #C8E6C9; }
.info-message { background: #E3F2FD; color: #1565C0; border: 1px solid #BBDEFB; }

.form-help {
  font-size: 0.8rem;
  color: var(--text-light);
  margin-top: 0.3rem;
  line-height: 1.4;
}

.btn-text-muted {
  background: none;
  border: none;
  color: var(--text-light);
  cursor: pointer;
  font-size: 0.85rem;
  text-decoration: underline;
  transition: color 0.2s;
  padding: 5px 0;
  font-family: inherit;
}

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

/* ============================================================
   RESPONSIVE STYLES (Mobile & Tablet)
   ============================================================ */

/* Hamburger Toggle - Hidden by default */
#mobile-menu-toggle {
  display: none;
  background: none;
  border: 1px solid var(--primary-color);
  border-radius: 4px;
  color: var(--primary-color);
  font-size: 1.8rem;
  cursor: pointer;
  padding: 0.2rem 0.6rem;
  transition: all 0.2s;
  z-index: 1101;
  margin-right: 1rem;
}

#mobile-menu-toggle:hover {
  background: rgba(62, 39, 35, 0.05);
}

/* Header Navigation Wrapper */
.header-nav-wrapper {
  display: flex;
  align-items: center;
  flex: 1;
  justify-content: flex-end;
}

@media (max-width: 1024px) {
  .header-container {
    height: auto;
    min-height: 70px;
    padding: 0.5rem 1rem;
    flex-wrap: wrap;
  }

  #app-title {
    font-size: 1.8rem;
  }

  #mobile-menu-toggle {
    display: block;
  }

  .header-nav-wrapper {
    position: fixed;
    top: 0;
    right: -100%; /* Hidden by default */
    width: 280px;
    height: 100vh;
    background: var(--white);
    flex-direction: column;
    justify-content: flex-start;
    align-items: stretch;
    padding: 5rem 1.5rem 2rem;
    box-shadow: -5px 0 15px rgba(0,0,0,0.1);
    transition: right 0.4s cubic-bezier(0.4, 0, 0.2, 1);
    z-index: 1100;
    overflow-y: auto;
  }

  .header-nav-wrapper.is-open {
    right: 0;
  }

  #search-container, #user-search-container {
    width: 100% !important;
    margin: 0.5rem 0;
  }

  #nav-controls {
    flex-direction: column;
    margin-left: 0;
    margin-top: 1.5rem;
    height: auto;
  }

  .user-greeting {
    width: 100%;
    margin-right: 0;
    margin-bottom: 1rem;
    justify-content: center;
  }

  .btn-text {
    width: 100%;
    padding: 1rem;
    border-bottom: 1px solid #E8E2D8;
    justify-content: flex-start;
  }

  .btn-text::after {
    display: none; /* Remove hover underline on mobile */
  }

  /* Overlay */
  .menu-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100vw;
    height: 100vh;
    background: rgba(0,0,0,0.4);
    backdrop-filter: blur(2px);
    z-index: 1050; /* Lower than header's 1100 */
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.3s;
  }

  .menu-overlay.is-active {
    opacity: 1;
    pointer-events: auto;
  }

  /* Main Layout */
  .app-layout {
    padding: 1rem;
  }

  .main-container {
    flex-direction: column;
    gap: 1.5rem;
    padding: 0;
  }

  #app-content {
    order: 2;
    padding: 1.5rem;
    width: 100%;
    max-width: 1000px; /* Limit width on tablet for readability */
    margin: 0 auto;
    overflow-x: hidden;
    box-sizing: border-box;
    background: #FFF;
    border-radius: 24px;
    box-shadow: 0 4px 20px rgba(0,0,0,0.03);
  }

  .app-sidebar {
    width: 100%;
    max-width: 1000px;
    margin: 0 auto;
    position: static;
    display: block;
    box-sizing: border-box;
    padding: 0 1.5rem;
  }

  .sidebar-left { order: 1; }
  .sidebar-right { order: 3; margin-bottom: 3rem; }

  /* Tablet Specific Adjustments */
  @media (min-width: 768px) {
    .main-container { padding: 0 2rem; }
    #app-content { padding: 3rem; }
    .app-sidebar { padding: 0 2rem; }
  }
}

@media (max-width: 600px) {
  #app-title {
    font-size: 1.5rem;
  }

  .page-title {
    font-size: 1.6rem;
  }

  .subject-grid {
    grid-template-columns: 1fr;
  }

  .article-content {
    padding: 1.5rem;
  }

  .article-content h1 {
    font-size: 1.8rem;
  }

  .article-meta {
    flex-direction: column;
    align-items: center;
    gap: 5px;
  }

  .quiz-section {
    position: static;
    margin-top: 2rem;
  }
}
