/* ====================================================================
   SunnyLab 배움터 - 공용 스타일
   과목 페이지는 <body class="theme-xxx"> 로 강조색을 바꿉니다.
   ==================================================================== */
:root {
  --bg: #f4f6fb;
  --card: #ffffff;
  --primary: #4f6df5;
  --primary-dark: #3a55d9;
  --accent: #16c79a;
  --danger: #ef5b5b;
  --text: #1f2533;
  --muted: #7a839a;
  --border: #e3e7f0;
  --shadow: 0 8px 24px rgba(40, 60, 120, 0.08);
}
/* 과목별 테마 색상 */
.theme-english { --primary: #4f6df5; --primary-dark: #3a55d9; }
.theme-ai      { --primary: #7c5cff; --primary-dark: #6344e0; }
.theme-japanese{ --primary: #ff5b7f; --primary-dark: #e84268; }
.theme-history { --primary: #c0392b; --primary-dark: #a52f22; }
.theme-science { --primary: #0d9488; --primary-dark: #0b7c72; }
.theme-python  { --primary: #306998; --primary-dark: #245179; }

* { box-sizing: border-box; margin: 0; padding: 0; }
body {
  font-family: "Segoe UI", "Malgun Gothic", "맑은 고딕", sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.6;
  -webkit-font-smoothing: antialiased;
}

/* ---------- 상단 / 헤더 ---------- */
.topbar {
  max-width: 960px;
  margin: 0 auto;
  padding: 16px;
}
.back-link {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  color: var(--muted);
  text-decoration: none;
  font-size: 0.9rem;
  font-weight: 600;
  background: var(--card);
  padding: 8px 14px;
  border-radius: 999px;
  box-shadow: var(--shadow);
  transition: all 0.15s ease;
}
.back-link:hover { color: var(--primary); transform: translateX(-2px); }

header {
  text-align: center;
  padding: 18px 16px 10px;
}
header h1 { font-size: 1.7rem; color: var(--primary); letter-spacing: -0.5px; }
header p { color: var(--muted); font-size: 0.9rem; margin-top: 4px; }

/* ---------- 탭 내비게이션 ---------- */
nav {
  display: flex;
  gap: 6px;
  justify-content: center;
  flex-wrap: wrap;
  padding: 14px 12px;
  position: sticky;
  top: 0;
  background: var(--bg);
  z-index: 10;
}
nav button {
  border: none;
  background: var(--card);
  color: var(--muted);
  padding: 10px 16px;
  border-radius: 999px;
  font-size: 0.92rem;
  font-weight: 600;
  cursor: pointer;
  box-shadow: var(--shadow);
  transition: all 0.15s ease;
}
nav button:hover { color: var(--primary); transform: translateY(-1px); }
nav button.active { background: var(--primary); color: #fff; }

main {
  max-width: 720px;
  margin: 0 auto;
  padding: 8px 16px 60px;
}
.panel { display: none; animation: fade 0.25s ease; }
.panel.active { display: block; }
@keyframes fade { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; transform: none; } }

.section-title { font-size: 1.15rem; margin-bottom: 12px; font-weight: 700; }
.hint { color: var(--muted); font-size: 0.85rem; margin-bottom: 16px; }

/* ---------- 플래시카드 ---------- */
.flashcard { perspective: 1200px; height: 260px; margin-bottom: 18px; }
.flashcard-inner {
  position: relative; width: 100%; height: 100%;
  transition: transform 0.55s; transform-style: preserve-3d; cursor: pointer;
}
.flashcard.flipped .flashcard-inner { transform: rotateY(180deg); }
.flash-face {
  position: absolute; inset: 0; backface-visibility: hidden;
  border-radius: 20px; background: var(--card); box-shadow: var(--shadow);
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  padding: 24px; text-align: center;
}
.flash-back { transform: rotateY(180deg); background: #eef2ff; }
.flash-word { font-size: 2rem; font-weight: 700; color: var(--primary); }
.flash-pos { color: var(--muted); font-size: 0.85rem; margin-top: 6px; }
.flash-mean { font-size: 1.6rem; font-weight: 700; }
.flash-ex { color: var(--muted); font-size: 0.95rem; margin-top: 14px; font-style: italic; }
.tap-hint { position: absolute; bottom: 12px; font-size: 0.75rem; color: var(--muted); }

.row { display: flex; gap: 10px; flex-wrap: wrap; }
.btn {
  border: none; border-radius: 12px; padding: 12px 18px;
  font-size: 0.95rem; font-weight: 600; cursor: pointer;
  transition: all 0.15s ease; flex: 1; min-width: 90px;
}
.btn-primary { background: var(--primary); color: #fff; }
.btn-primary:hover { background: var(--primary-dark); }
.btn-ghost { background: var(--card); color: var(--text); box-shadow: var(--shadow); }
.btn-accent { background: var(--accent); color: #fff; }
.btn-danger { background: var(--danger); color: #fff; }
.btn:active { transform: scale(0.97); }

.progress { text-align: center; color: var(--muted); font-size: 0.9rem; margin: 10px 0 14px; }

/* ---------- 퀴즈 ---------- */
.quiz-q { font-size: 1.2rem; font-weight: 700; margin-bottom: 4px; }
.quiz-sub { color: var(--muted); font-size: 0.85rem; margin-bottom: 16px; }
.quiz-options { display: grid; gap: 10px; }
.quiz-opt {
  background: var(--card); border: 2px solid var(--border);
  border-radius: 12px; padding: 14px 16px; cursor: pointer;
  font-size: 1rem; text-align: left; transition: all 0.15s ease;
}
.quiz-opt:hover { border-color: var(--primary); }
.quiz-opt.correct { border-color: var(--accent); background: #e8fbf4; }
.quiz-opt.wrong { border-color: var(--danger); background: #fdeaea; }
.quiz-opt.disabled { pointer-events: none; opacity: 0.85; }
.quiz-feedback { margin: 14px 0; font-weight: 600; min-height: 24px; }

/* ---------- 회화 / 카테고리 ---------- */
.cat-tabs { display: flex; gap: 8px; flex-wrap: wrap; margin-bottom: 16px; }
.cat-tab {
  background: var(--card); border: 1px solid var(--border);
  border-radius: 999px; padding: 7px 14px; font-size: 0.85rem;
  cursor: pointer; font-weight: 600; color: var(--muted);
}
.cat-tab.active { background: var(--accent); color: #fff; border-color: var(--accent); }
.phrase {
  background: var(--card); border-radius: 14px; padding: 16px;
  box-shadow: var(--shadow); margin-bottom: 12px;
}
.phrase-en { font-size: 1.1rem; font-weight: 700; }
.phrase-ko { color: var(--muted); margin-top: 4px; }
.codeblock {
  background: #1e2330; color: #e6e9f0; border-radius: 10px;
  padding: 14px 16px; margin: 10px 0 4px;
  font-family: "Consolas", "D2Coding", "Courier New", monospace;
  font-size: 0.9rem; line-height: 1.55; overflow-x: auto; white-space: pre;
}

/* ---------- 코드 실행기 ---------- */
.code-editor {
  width: 100%; min-height: 220px; border: 2px solid var(--border); border-radius: 12px;
  padding: 14px 16px; tab-size: 4;
  font-family: "Consolas", "D2Coding", "Courier New", monospace;
  font-size: 0.95rem; line-height: 1.5; resize: vertical;
  background: #1e2330; color: #e6e9f0;
}
.code-editor:focus { outline: none; border-color: var(--primary); }
.run-output {
  background: #0f1320; color: #d6f5e0; border-radius: 12px; padding: 14px 16px; margin-top: 12px;
  font-family: "Consolas", "D2Coding", "Courier New", monospace;
  font-size: 0.9rem; line-height: 1.5; white-space: pre-wrap; min-height: 60px; overflow-x: auto;
}
.run-status { color: var(--muted); font-size: 0.85rem; margin-top: 10px; text-align: center; }
.example-picker {
  flex: 1; min-width: 150px; border: none; border-radius: 12px;
  padding: 12px 16px; font-size: 0.95rem; font-weight: 600; cursor: pointer;
  font-family: inherit; background: var(--card); color: var(--text); box-shadow: var(--shadow);
}
.example-picker:focus { outline: none; }
.speak-btn {
  margin-top: 10px; background: #eef2ff; border: none; color: var(--primary);
  border-radius: 10px; padding: 6px 12px; cursor: pointer; font-weight: 600; font-size: 0.85rem;
}

/* ---------- 단어장 / 노트 ---------- */
.form-grid { display: grid; gap: 10px; margin-bottom: 18px; }
.form-grid input {
  border: 2px solid var(--border); border-radius: 12px;
  padding: 12px 14px; font-size: 1rem; font-family: inherit;
}
.form-grid input:focus { outline: none; border-color: var(--primary); }
.word-item {
  background: var(--card); border-radius: 12px; padding: 14px 16px;
  box-shadow: var(--shadow); margin-bottom: 10px;
  display: flex; justify-content: space-between; align-items: center; gap: 12px;
}
.word-item .w-en { font-weight: 700; }
.word-item .w-ko { color: var(--muted); font-size: 0.9rem; }
.del-btn {
  background: none; border: none; color: var(--danger); cursor: pointer;
  font-size: 1.3rem; line-height: 1; padding: 4px 8px; border-radius: 8px;
}
.del-btn:hover { background: #fdeaea; }
.empty { text-align: center; color: var(--muted); padding: 30px 0; }

/* ---------- 타자 연습 ---------- */
.typing-box { text-align: center; }
.typing-word { font-size: 2.4rem; font-weight: 800; color: var(--primary); letter-spacing: 1px; }
.typing-mean { color: var(--muted); margin: 6px 0 18px; }
.typing-input {
  width: 100%; border: 2px solid var(--border); border-radius: 12px;
  padding: 14px; font-size: 1.3rem; text-align: center; font-family: inherit;
}
.typing-input:focus { outline: none; border-color: var(--primary); }
.typing-input.ok { border-color: var(--accent); background: #e8fbf4; }
.typing-input.err { border-color: var(--danger); background: #fdeaea; }
.stats { display: flex; gap: 14px; justify-content: center; margin-top: 16px; color: var(--muted); font-size: 0.9rem; }
.stats b { color: var(--text); font-size: 1.1rem; }

.score-badge {
  display: inline-block; background: #eef2ff; color: var(--primary);
  padding: 4px 12px; border-radius: 999px; font-weight: 700; font-size: 0.85rem;
}
footer { text-align: center; color: var(--muted); font-size: 0.8rem; padding: 20px; }

/* ====================================================================
   로그인 / 계정 UI
   ==================================================================== */
.auth-bar {
  position: fixed; top: 12px; right: 14px; z-index: 60;
  display: flex; align-items: center; gap: 8px;
}
.auth-bar .auth-name {
  background: var(--card); box-shadow: var(--shadow); border-radius: 999px;
  padding: 7px 14px; font-size: 0.82rem; font-weight: 700; color: var(--text);
}
.auth-bar button {
  border: none; border-radius: 999px; padding: 8px 14px;
  font-size: 0.82rem; font-weight: 700; cursor: pointer; box-shadow: var(--shadow);
}
.auth-bar .auth-login-btn { background: var(--primary); color: #fff; }
.auth-bar .auth-acct-btn { background: var(--card); color: var(--primary); }
.auth-bar .auth-logout-btn { background: var(--card); color: var(--muted); }

.auth-modal-bg {
  position: fixed; inset: 0; background: rgba(20, 28, 50, 0.45);
  z-index: 100; display: flex; align-items: center; justify-content: center; padding: 16px;
}
.auth-modal {
  background: var(--card); border-radius: 18px; width: 100%; max-width: 380px;
  padding: 22px 24px; box-shadow: 0 20px 50px rgba(20, 30, 60, 0.25);
}
.auth-modal h2 { font-size: 1.2rem; }
.auth-close { float: right; background: none; border: none; font-size: 1.5rem; line-height: 1; cursor: pointer; color: var(--muted); }
.auth-tabs { display: flex; gap: 8px; margin: 16px 0; }
.auth-tabs button {
  flex: 1; border: none; border-radius: 10px; padding: 10px; font-weight: 700;
  cursor: pointer; background: var(--bg); color: var(--muted); font-family: inherit;
}
.auth-tabs button.active { background: var(--primary); color: #fff; }
.auth-form { display: none; flex-direction: column; gap: 10px; }
.auth-form.active { display: flex; }
.auth-form input {
  border: 2px solid var(--border); border-radius: 10px; padding: 11px 13px;
  font-size: 0.95rem; font-family: inherit;
}
.auth-form input:focus { outline: none; border-color: var(--primary); }
.auth-form .auth-submit {
  background: var(--primary); color: #fff; border: none; border-radius: 10px;
  padding: 12px; font-weight: 700; cursor: pointer; margin-top: 2px;
}
.auth-form .auth-submit:disabled { opacity: 0.6; cursor: default; }
.auth-err { color: var(--danger); font-size: 0.85rem; min-height: 18px; }
.auth-ok { color: var(--accent); font-size: 0.85rem; min-height: 18px; font-weight: 600; }
.auth-hint-sm { font-size: 0.78rem; color: var(--muted); margin-top: 4px; }
.auth-forgot-link { display: block; text-align: center; font-size: 0.8rem; color: var(--muted); cursor: pointer; text-decoration: underline; margin-top: 6px; }
.auth-form label { font-size: 0.78rem; color: var(--muted); font-weight: 700; margin-top: 4px; }
.auth-form input:disabled { background: var(--bg); color: var(--muted); }
.acct-divider { border: none; border-top: 1px solid var(--border); margin: 18px 0 14px; }
.acct-subtitle { font-size: 1rem; margin-bottom: 10px; }

/* 허브: 내 학습 현황 */
.hub-progress {
  max-width: 880px; margin: 0 auto 4px; padding: 18px 22px;
  background: var(--card); border-radius: 18px; box-shadow: var(--shadow);
}
.hub-progress h3 { font-size: 1.05rem; margin-bottom: 10px; }
.hub-progress .hp-empty { color: var(--muted); font-size: 0.9rem; }
.hub-progress .hp-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(200px, 1fr)); gap: 10px; }
.hub-progress .hp-item {
  display: flex; flex-direction: column; gap: 2px;
  background: var(--bg); border-radius: 12px; padding: 10px 14px;
}
.hub-progress .hp-item b { font-size: 0.95rem; }
.hub-progress .hp-item span { font-size: 0.8rem; color: var(--muted); }
.hub-progress .hp-item em { font-size: 0.72rem; color: var(--muted); font-style: normal; opacity: 0.7; }

/* ====================================================================
   배움터 허브(메인 페이지) 전용
   ==================================================================== */
.hub-header {
  text-align: center;
  padding: 50px 20px 30px;
}
.hub-logo { font-size: 3rem; }
.hub-header h1 {
  font-size: 2.2rem;
  margin-top: 8px;
  background: linear-gradient(135deg, #4f6df5, #7c5cff);
  -webkit-background-clip: text;
  background-clip: text;
  -webkit-text-fill-color: transparent;
  letter-spacing: -1px;
}
.hub-header p { color: var(--muted); margin-top: 10px; font-size: 1rem; }

.subject-grid {
  max-width: 880px;
  margin: 0 auto;
  padding: 10px 16px 60px;
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(240px, 1fr));
  gap: 18px;
}
.subject-card {
  display: flex;
  flex-direction: column;
  background: var(--card);
  border-radius: 18px;
  padding: 26px 22px;
  box-shadow: var(--shadow);
  text-decoration: none;
  color: var(--text);
  transition: transform 0.18s ease, box-shadow 0.18s ease;
  border-top: 4px solid var(--sc, var(--primary));
}
.subject-card:hover { transform: translateY(-4px); box-shadow: 0 14px 32px rgba(40,60,120,0.14); }
.subject-card .sc-icon { font-size: 2.4rem; }
.subject-card .sc-name { font-size: 1.3rem; font-weight: 800; margin-top: 12px; }
.subject-card .sc-desc { color: var(--muted); font-size: 0.9rem; margin-top: 8px; flex: 1; }
.subject-card .sc-go {
  margin-top: 18px; font-weight: 700; font-size: 0.9rem;
  color: var(--sc, var(--primary));
}
.subject-card .sc-tags { margin-top: 12px; display: flex; flex-wrap: wrap; gap: 6px; }
.subject-card .sc-tag {
  font-size: 0.72rem; background: #eef2ff; color: var(--muted);
  padding: 3px 9px; border-radius: 999px; font-weight: 600;
}
/* 준비중 카드 */
.subject-card.soon {
  border-top-color: var(--border);
  cursor: default;
  opacity: 0.75;
  align-items: center;
  justify-content: center;
  text-align: center;
  border: 2px dashed var(--border);
  background: transparent;
}
.subject-card.soon:hover { transform: none; box-shadow: var(--shadow); }
.subject-card.soon .sc-icon { opacity: 0.5; }
