/* ====================================================
   FE Study Site — style.css
   Primary: Indigo #4f46e5  /  Secondary: Purple #7c3aed
   ==================================================== */
:root {
  --primary:       #4f46e5;
  --primary-dark:  #3730a3;
  --primary-mid:   #6366f1;
  --primary-light: #e0e7ff;
  --primary-bg:    #f0f0ff;
  --accent:        #7c3aed;
  --success:       #059669;
  --success-light: #d1fae5;
  --warning:       #d97706;
  --warning-light: #fef3c7;
  --danger:        #dc2626;
  --danger-light:  #fee2e2;
  --info:          #0284c7;
  --info-light:    #e0f2fe;
  --text:          #1e293b;
  --text-muted:    #64748b;
  --bg:            #f1f5f9;
  --card-bg:       #ffffff;
  --border:        #e2e8f0;
  --radius:        12px;
  --radius-sm:     8px;
  --shadow:        0 2px 8px rgba(0,0,0,0.07);
  --shadow-md:     0 4px 16px rgba(0,0,0,0.11);
}

/* === RESET === */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
html { scroll-behavior: smooth; }
body {
  font-family: 'Hiragino Kaku Gothic ProN', 'Hiragino Sans', 'Meiryo', 'Yu Gothic', sans-serif;
  background: var(--bg);
  color: var(--text);
  font-size: 16px;
  line-height: 1.75;
  -webkit-font-smoothing: antialiased;
}

/* === HEADER === */
.site-header {
  background: linear-gradient(135deg, var(--primary) 0%, var(--accent) 100%);
  color: white;
  padding: 12px 16px;
  position: sticky;
  top: 0;
  z-index: 100;
  box-shadow: 0 2px 10px rgba(79,70,229,0.35);
}
.site-header .header-inner {
  max-width: 800px;
  margin: 0 auto;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}
.site-header .header-title { font-size: 1.05em; font-weight: 800; letter-spacing: 0.01em; }
.site-header .header-back {
  color: rgba(255,255,255,0.9);
  text-decoration: none;
  font-size: 0.85em;
  padding: 4px 10px;
  border: 1px solid rgba(255,255,255,0.4);
  border-radius: 20px;
  transition: background 0.2s;
  white-space: nowrap;
}
.site-header .header-back:hover { background: rgba(255,255,255,0.15); }

/* === MAIN === */
main {
  max-width: 800px;
  margin: 0 auto;
  padding: 16px 12px 48px;
}

/* === CARD === */
.card {
  background: var(--card-bg);
  border-radius: var(--radius);
  padding: 20px;
  margin-bottom: 16px;
  box-shadow: var(--shadow);
  border: 1px solid var(--border);
}
.card h2 {
  font-size: 1.05em;
  font-weight: 800;
  margin-bottom: 14px;
  color: var(--text);
}

/* === CONCLUSION CARD === */
.conclusion-card {
  background: linear-gradient(135deg, var(--primary-light) 0%, #f0f9ff 100%);
  border-left: 4px solid var(--primary);
}
.conclusion-card h2 { color: var(--primary-dark); font-size: 0.9em; margin-bottom: 6px; }
.conclusion-card p { font-size: 0.95em; line-height: 1.8; }

/* === PAGE HEADER === */
.page-header { margin-bottom: 18px; }
.page-meta { display: flex; gap: 6px; flex-wrap: wrap; margin-bottom: 10px; }
.page-header h1 { font-size: 1.5em; font-weight: 900; color: var(--text); line-height: 1.3; }

.category-badge, .time-badge, .difficulty-badge, .frequency-badge {
  display: inline-flex;
  align-items: center;
  gap: 3px;
  padding: 3px 10px;
  border-radius: 20px;
  font-size: 0.78em;
  font-weight: 700;
}
.category-badge   { background: var(--primary-light); color: var(--primary-dark); }
.time-badge       { background: #f1f5f9; color: var(--text-muted); }
.difficulty-badge { background: var(--warning-light); color: var(--warning); }
.frequency-badge  { background: var(--danger-light); color: var(--danger); }

/* === KEYWORD === */
.keyword { color: var(--primary); font-weight: 700; }

/* === BADGE (inline) === */
.badge {
  display: inline-block;
  padding: 1px 7px;
  border-radius: 4px;
  font-size: 0.72em;
  font-weight: 700;
  margin-left: 4px;
  vertical-align: middle;
}
.badge-important { background: var(--danger); color: white; }
.badge-frequent  { background: var(--accent); color: white; }
.badge-tip       { background: var(--success); color: white; }
.badge-new       { background: var(--info); color: white; }

/* === HIGHLIGHT BOX === */
.highlight-box {
  background: var(--info-light);
  border-left: 4px solid var(--info);
  border-radius: 0 var(--radius-sm) var(--radius-sm) 0;
  padding: 12px 16px;
  margin: 12px 0;
  font-size: 0.92em;
}
.highlight-box.amber  { background: var(--warning-light); border-color: var(--warning); }
.highlight-box.green  { background: var(--success-light); border-color: var(--success); }
.highlight-box.red    { background: var(--danger-light);  border-color: var(--danger); }
.highlight-box.purple { background: #f3e8ff; border-color: var(--accent); }
.highlight-box.indigo { background: var(--primary-light); border-color: var(--primary); }

/* === CHECK LIST === */
.check-list { list-style: none; padding: 0; }
.check-list li {
  padding: 7px 0 7px 28px;
  position: relative;
  border-bottom: 1px solid #f1f5f9;
  font-size: 0.92em;
}
.check-list li:last-child { border-bottom: none; }
.check-list li::before { content: '✓'; position: absolute; left: 0; color: var(--success); font-weight: 700; }

/* === COMPARE GRID === */
.compare-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
  margin: 12px 0;
}
.compare-card {
  background: #f8fafc;
  border: 1.5px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 14px;
}
.compare-card-title {
  font-weight: 700;
  color: var(--primary);
  font-size: 0.9em;
  margin-bottom: 8px;
  padding-bottom: 6px;
  border-bottom: 2px solid var(--primary-light);
}
.compare-card p { font-size: 0.88em; line-height: 1.65; }
@media (max-width: 480px) { .compare-grid { grid-template-columns: 1fr; } }

/* === DIAGRAM === */
.diagram-wrap {
  background: #f8fafc;
  border: 1.5px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 6px;
  margin: 12px 0;
  overflow-x: auto;
}
.diagram-box { min-height: 60px; }

/* === CODE BLOCK === */
.code-block {
  background: #1e293b;
  color: #e2e8f0;
  border-radius: var(--radius-sm);
  padding: 16px;
  font-family: 'Courier New', 'Consolas', 'SF Mono', monospace;
  font-size: 0.88em;
  line-height: 1.7;
  overflow-x: auto;
  margin: 12px 0;
  white-space: pre;
}
.code-comment  { color: #64748b; }
.code-keyword  { color: #818cf8; font-weight: 700; }
.code-string   { color: #34d399; }
.code-number   { color: #fb923c; }

/* === PSEUDOCODE === */
.pseudocode {
  background: #0f172a;
  color: #a5b4fc;
  border: 2px solid var(--primary-dark);
  border-radius: var(--radius-sm);
  padding: 16px;
  font-family: 'Courier New', 'Consolas', monospace;
  font-size: 0.9em;
  line-height: 1.9;
  overflow-x: auto;
  margin: 12px 0;
  white-space: pre;
}
.pseudo-keyword { color: #f472b6; font-weight: 700; }
.pseudo-comment { color: #475569; font-style: italic; }
.pseudo-var     { color: #86efac; }
.pseudo-num     { color: #fbbf24; }
.pseudo-str     { color: #34d399; }
.pseudo-hl      { background: rgba(244,114,182,0.15); border-radius: 3px; }

/* === TRACE TABLE === */
.trace-wrap { overflow-x: auto; margin: 12px 0; }
.trace-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.85em;
  min-width: 300px;
}
.trace-table th {
  background: var(--primary);
  color: white;
  padding: 8px 12px;
  text-align: center;
  font-weight: 700;
}
.trace-table td {
  padding: 7px 12px;
  text-align: center;
  border: 1px solid var(--border);
}
.trace-table tr:nth-child(even) { background: #f8fafc; }
.trace-table .hl-row  { background: var(--warning-light) !important; }
.trace-table .res-row { background: var(--success-light) !important; font-weight: 700; }

/* === EXAM CARD === */
.exam-card { border-left: 4px solid var(--primary); }
.exam-card h2 { color: var(--primary-dark); }

/* === WARNING CARD === */
.warning-card { border-left: 4px solid var(--danger); background: #fff8f8; }
.warning-card h2 { color: var(--danger); }

/* === QUIZ === */
.quiz-card h2 { color: var(--primary-dark); margin-bottom: 16px; }
.quiz-item { margin-bottom: 26px; }
.quiz-question {
  font-weight: 700;
  margin-bottom: 10px;
  padding: 10px 14px;
  background: var(--primary-light);
  border-radius: var(--radius-sm);
  font-size: 0.92em;
  border-left: 3px solid var(--primary);
}
.quiz-choices { display: flex; flex-direction: column; gap: 8px; }
.quiz-choices button {
  background: white;
  border: 2px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 10px 14px;
  text-align: left;
  cursor: pointer;
  font-size: 0.9em;
  transition: all 0.18s;
  font-family: inherit;
  color: var(--text);
  line-height: 1.5;
}
.quiz-choices button:hover:not(:disabled) { border-color: var(--primary); background: var(--primary-light); }
.quiz-choices button.correct   { background: var(--success-light); border-color: var(--success); color: var(--success); font-weight: 700; }
.quiz-choices button.incorrect { background: var(--danger-light);  border-color: var(--danger);  color: var(--danger); }
.quiz-choices button:disabled  { cursor: default; opacity: 0.85; }
.quiz-explanation {
  display: none;
  margin-top: 10px;
  padding: 12px 14px;
  background: var(--success-light);
  border-radius: var(--radius-sm);
  font-size: 0.88em;
  border-left: 3px solid var(--success);
  line-height: 1.7;
}

/* === COMPLETE BUTTON === */
.btn-complete {
  display: block;
  width: 100%;
  padding: 16px;
  background: linear-gradient(135deg, var(--primary), var(--accent));
  color: white;
  border: none;
  border-radius: var(--radius);
  font-size: 1em;
  font-weight: 800;
  cursor: pointer;
  margin: 20px 0;
  transition: all 0.2s;
  font-family: inherit;
  letter-spacing: 0.02em;
  box-shadow: 0 4px 12px rgba(79,70,229,0.3);
}
.btn-complete:hover:not(.completed) { transform: translateY(-2px); box-shadow: 0 6px 18px rgba(79,70,229,0.4); }
.btn-complete.completed {
  background: linear-gradient(135deg, var(--success), #10b981);
  box-shadow: 0 4px 12px rgba(5,150,105,0.3);
  cursor: default;
}

/* === PAGE NAV === */
.page-nav {
  display: flex;
  justify-content: space-between;
  gap: 8px;
  margin: 12px 0;
}
.nav-btn {
  flex: 1;
  display: block;
  text-align: center;
  padding: 11px 8px;
  background: white;
  border: 2px solid var(--primary);
  color: var(--primary);
  border-radius: var(--radius-sm);
  text-decoration: none;
  font-size: 0.82em;
  font-weight: 700;
  transition: all 0.18s;
  min-width: 0;
}
.nav-btn:hover { background: var(--primary); color: white; }
.nav-btn.nav-home { background: var(--primary-light); border-color: var(--primary-light); color: var(--primary-dark); flex: 0.6; }
.nav-btn.disabled { opacity: 0.35; pointer-events: none; }

/* === ALGO CELLS === */
.algo-row { display: flex; gap: 6px; justify-content: center; margin: 8px 0; flex-wrap: wrap; }
.algo-cell {
  width: 40px; height: 40px;
  border: 2px solid var(--border);
  border-radius: 6px;
  display: flex; align-items: center; justify-content: center;
  font-weight: 700; font-size: 0.95em;
  background: white; transition: all 0.2s;
}
.algo-cell.active    { background: var(--warning-light); border-color: var(--warning); }
.algo-cell.comparing { background: var(--info-light);    border-color: var(--info); }
.algo-cell.sorted    { background: var(--success-light); border-color: var(--success); }
.algo-cell.found     { background: var(--danger-light);  border-color: var(--danger); }
.algo-cell.pivot     { background: #f3e8ff; border-color: var(--accent); }
.algo-cell.check     { background: var(--primary-light); border-color: var(--primary); }
@media (max-width: 480px) { .algo-cell { width: 34px; height: 34px; font-size: 0.82em; } }

/* === STEP LIST === */
.step-list { display: flex; flex-direction: column; gap: 12px; }
.step-item { display: flex; gap: 14px; align-items: flex-start; }
.step-num {
  background: var(--primary); color: white;
  width: 32px; height: 32px; border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  font-weight: 700; font-size: 0.9em; flex-shrink: 0; margin-top: 2px;
}
.step-title { font-weight: 700; margin-bottom: 3px; font-size: 0.95em; }
.step-desc  { font-size: 0.88em; color: var(--text-muted); line-height: 1.6; }

/* === INDEX: HERO === */
.hero {
  background: linear-gradient(135deg, var(--primary) 0%, var(--accent) 100%);
  color: white;
  border-radius: var(--radius);
  padding: 28px 20px 24px;
  margin-bottom: 20px;
  text-align: center;
  position: relative;
  overflow: hidden;
}
.hero::before {
  content: '';
  position: absolute; inset: 0;
  background: url("data:image/svg+xml,%3Csvg width='60' height='60' viewBox='0 0 60 60' xmlns='http://www.w3.org/2000/svg'%3E%3Cg fill='none' fill-rule='evenodd'%3E%3Cg fill='%23ffffff' fill-opacity='0.04'%3E%3Cpath d='M36 34v-4h-2v4h-4v2h4v4h2v-4h4v-2h-4zm0-30V0h-2v4h-4v2h4v4h2V6h4V4h-4zM6 34v-4H4v4H0v2h4v4h2v-4h4v-2H6zM6 4V0H4v4H0v2h4v4h2V6h4V4H6z'/%3E%3C/g%3E%3C/g%3E%3C/svg%3E");
}
.hero-tag { font-size: 0.78em; background: rgba(255,255,255,0.2); padding: 2px 10px; border-radius: 20px; display: inline-block; margin-bottom: 10px; }
.hero h1  { font-size: 1.45em; font-weight: 900; margin-bottom: 8px; position: relative; }
.hero p   { font-size: 0.9em; opacity: 0.9; position: relative; }

/* === INDEX: PROGRESS === */
.progress-section {
  background: white;
  border-radius: var(--radius);
  padding: 20px;
  margin-bottom: 16px;
  box-shadow: var(--shadow);
  border: 1px solid var(--border);
}
.progress-label {
  display: flex; justify-content: space-between;
  margin-bottom: 8px; font-size: 0.9em; font-weight: 700;
}
.progress-bar-wrap { background: #e2e8f0; border-radius: 20px; height: 13px; overflow: hidden; }
.progress-bar-fill {
  background: linear-gradient(90deg, var(--primary), var(--accent));
  height: 100%; border-radius: 20px; transition: width 0.6s ease; width: 0%;
}
.progress-stats {
  display: grid; grid-template-columns: repeat(3, 1fr);
  gap: 10px; margin-top: 16px;
}
.stat-card { text-align: center; background: #f8fafc; border-radius: var(--radius-sm); padding: 10px 6px; }
.stat-number { font-size: 1.6em; font-weight: 900; color: var(--primary); line-height: 1.1; }
.stat-label  { font-size: 0.74em; color: var(--text-muted); margin-top: 2px; }

/* === INDEX: TODAY === */
.today-section {
  background: linear-gradient(135deg, #fef3c7 0%, #fffbeb 100%);
  border: 2px solid var(--warning);
  border-radius: var(--radius);
  padding: 16px 18px;
  margin-bottom: 16px;
}
.today-section h2 { color: var(--warning); font-size: 1em; margin-bottom: 12px; }
.today-list { display: flex; flex-direction: column; gap: 8px; }
.today-item {
  display: flex; align-items: center; gap: 12px;
  background: white; border-radius: var(--radius-sm);
  padding: 10px 14px;
  text-decoration: none; color: var(--text);
  border: 1.5px solid var(--border); transition: all 0.2s;
}
.today-item:hover { border-color: var(--warning); }
.today-num {
  background: var(--warning); color: white;
  width: 26px; height: 26px; border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  font-size: 0.8em; font-weight: 700; flex-shrink: 0;
}
.today-title { font-weight: 600; font-size: 0.92em; }
.today-meta  { font-size: 0.76em; color: var(--text-muted); }

/* === INDEX: SECTION & LIST === */
.section-title {
  font-size: 1.05em; font-weight: 800; color: var(--text);
  margin: 22px 0 10px;
  padding-left: 12px;
  border-left: 4px solid var(--primary);
  display: flex; align-items: center; gap: 8px;
}
.section-count { font-size: 0.8em; font-weight: 600; color: var(--text-muted); background: #f1f5f9; padding: 1px 8px; border-radius: 20px; }

.page-list { display: flex; flex-direction: column; gap: 6px; }
.page-list-item {
  display: flex; align-items: center; gap: 12px;
  background: white; border-radius: var(--radius-sm);
  padding: 11px 14px;
  text-decoration: none; color: var(--text);
  border: 1.5px solid var(--border); transition: all 0.18s;
}
.page-list-item:hover { border-color: var(--primary); transform: translateX(3px); }
.page-list-item.done  { border-color: var(--success); background: #f0fdf4; }

.check-icon {
  width: 22px; height: 22px;
  border: 2px solid var(--border);
  border-radius: 50%;
  flex-shrink: 0;
  display: flex; align-items: center; justify-content: center;
  font-size: 0.75em; color: white; background: white;
}
.page-list-item.done .check-icon { background: var(--success); border-color: var(--success); }
.page-list-item.done .check-icon::after { content: '✓'; }

.item-info  { flex: 1; min-width: 0; }
.item-title { font-weight: 600; font-size: 0.91em; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.item-meta  { font-size: 0.75em; color: var(--text-muted); display: flex; gap: 8px; margin-top: 2px; }

.item-badges { display: flex; gap: 4px; flex-shrink: 0; }
.star-badge  { font-size: 0.72em; color: var(--text-muted); }
.star-badge.high { color: var(--danger); font-weight: 700; }

/* === SPONSOR === */
.sponsor-area { margin-top: 36px; padding-top: 20px; border-top: 1px solid var(--border); text-align: center; }
.sponsor-label { font-size: 0.75em; color: var(--text-muted); margin-bottom: 12px; }
.sponsor-inner { display: flex; flex-wrap: wrap; justify-content: center; gap: 12px; }

/* === UTILITY === */
p + p { margin-top: 8px; }
strong { font-weight: 700; }
small  { font-size: 0.85em; color: var(--text-muted); }
.mt8 { margin-top: 8px; }
.mt12 { margin-top: 12px; }
.text-center { text-align: center; }
.text-muted { color: var(--text-muted); font-size: 0.88em; }

/* === TOUCH OPTIMIZATION === */
a, button {
  -webkit-tap-highlight-color: transparent;
  touch-action: manipulation;
}

/* Active states (hover doesn't fire on touch devices) */
.quiz-choices button:active:not(:disabled) {
  transform: scale(0.98);
  border-color: var(--primary);
  background: var(--primary-light);
}
.nav-btn:active    { background: var(--primary); color: white; }
.today-item:active { border-color: var(--warning); background: #fffbeb; }
.page-list-item:active { border-color: var(--primary); background: var(--primary-light); }
.btn-complete:active:not(.completed) { transform: translateY(1px); }

/* Minimum touch target sizes (Google Material: 48px) */
.quiz-choices button { min-height: 48px; }
.nav-btn             { min-height: 44px; }
.btn-complete        { min-height: 52px; }
.today-item          { min-height: 52px; }
.page-list-item      { min-height: 48px; }

/* === SAFE AREA (iPhone notch / home bar) === */
.site-header {
  padding-left:  max(16px, env(safe-area-inset-left));
  padding-right: max(16px, env(safe-area-inset-right));
}
main {
  padding-left:  max(12px, env(safe-area-inset-left));
  padding-right: max(12px, env(safe-area-inset-right));
  padding-bottom: max(48px, calc(env(safe-area-inset-bottom) + 36px));
}

/* === HORIZONTAL SCROLL INDICATOR === */
.pseudocode, .code-block, .trace-wrap, .diagram-wrap {
  -webkit-overflow-scrolling: touch;
  scroll-behavior: smooth;
}
/* Fade edge on scrollable blocks */
.pseudocode, .code-block {
  background-image:
    linear-gradient(to right, transparent 85%, rgba(15,23,42,0.85)),
    linear-gradient(to left,  transparent 85%, rgba(15,23,42,0.85));
  background-attachment: local, local;
  background-size: 100% 100%;
}
/* Reset when not overflowing (no visual effect if content fits) */
.pseudocode:not([data-overflow]), .code-block:not([data-overflow]) {
  background-image: none;
}

/* === RESPONSIVE === */
@media (max-width: 600px) {
  body { font-size: 15px; }
  main { padding: 12px 10px 36px; }
  .card { padding: 16px 14px; }
  .page-header h1 { font-size: 1.3em; }
  .progress-stats { gap: 6px; }
  .stat-number { font-size: 1.35em; }
}

@media (max-width: 480px) {
  /* Typography */
  body { font-size: 14.5px; }
  .card h2 { font-size: 1em; }
  .check-list li { font-size: 0.9em; }
  .highlight-box  { font-size: 0.9em; padding: 10px 12px; }

  /* Header: prevent overflow on tiny screens */
  .site-header .header-title {
    font-size: 0.88em;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    min-width: 0;
  }
  .site-header .header-inner { gap: 6px; }

  /* Code / pseudocode */
  .pseudocode { font-size: 0.78em; line-height: 1.75; padding: 12px; }
  .code-block  { font-size: 0.78em; padding: 12px; }

  /* Trace table */
  .trace-table { font-size: 0.78em; }
  .trace-table th,
  .trace-table td { padding: 6px 8px; }

  /* Quiz */
  .quiz-question { font-size: 0.88em; padding: 9px 12px; }
  .quiz-choices button { font-size: 0.88em; padding: 12px 12px; }
  .quiz-explanation    { font-size: 0.86em; padding: 10px 12px; }

  /* Page nav: prev/next side-by-side, home full-width below */
  .page-nav {
    display: grid;
    grid-template-columns: 1fr 1fr;
    grid-template-rows: auto auto;
    gap: 8px;
  }
  .nav-btn.nav-prev { grid-column: 1; grid-row: 1; }
  .nav-btn.nav-next { grid-column: 2; grid-row: 1; }
  .nav-btn.nav-home { grid-column: 1 / -1; grid-row: 2; flex: unset; }

  /* Compare grid: always single column on tiny screens */
  .compare-grid { grid-template-columns: 1fr; }

  /* Hero */
  .hero { padding: 22px 16px 20px; }
  .hero h1 { font-size: 1.25em; }

  /* Step list */
  .step-num { width: 28px; height: 28px; font-size: 0.85em; }
}
