/* Typing Dojo - Atlassian-inspired Design */
:root {
  --primary: #0052CC;
  --primary-hover: #0065FF;
  --primary-light: #DEEBFF;
  --bg: #FAFBFC;
  --surface: #FFFFFF;
  --text: #172B4D;
  --text-secondary: #5E6C84;
  --border: #DFE1E6;
  --success: #00875A;
  --error: #DE350B;
  --warning: #FF991F;
  --shadow: 0 1px 3px rgba(9,30,66,0.13);
  --shadow-lg: 0 8px 16px rgba(9,30,66,0.15);
  --radius: 8px;
  --font: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Noto Sans JP', sans-serif;
  --transition: 0.2s ease;
}

[data-theme="dark"] {
  --bg: #1B2638;
  --surface: #243044;
  --text: #E4E7EB;
  --text-secondary: #A5ADBA;
  --border: #344563;
  --shadow: 0 1px 3px rgba(0,0,0,0.3);
  --shadow-lg: 0 8px 16px rgba(0,0,0,0.4);
  --primary-light: #1a3a6b;
}

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

body {
  font-family: var(--font);
  background: var(--bg);
  color: var(--text);
  line-height: 1.6;
  transition: background var(--transition), color var(--transition);
  min-height: 100vh;
}

/* Header */
#app-header {
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  box-shadow: var(--shadow);
  position: sticky;
  top: 0;
  z-index: 100;
}

.header-inner {
  max-width: 1100px;
  margin: 0 auto;
  padding: 0 20px;
  display: flex;
  align-items: center;
  height: 56px;
  gap: 16px;
}

.logo {
  font-size: 20px;
  font-weight: 700;
  color: var(--primary);
  white-space: nowrap;
}

#main-nav {
  display: flex;
  gap: 4px;
  flex: 1;
  justify-content: center;
}

.nav-btn {
  background: none;
  border: none;
  padding: 8px 16px;
  font-size: 14px;
  font-weight: 500;
  color: var(--text-secondary);
  cursor: pointer;
  border-radius: var(--radius);
  transition: all var(--transition);
  white-space: nowrap;
}

.nav-btn:hover { background: var(--primary-light); color: var(--primary); }
.nav-btn.active { background: var(--primary-light); color: var(--primary); font-weight: 600; }

.header-actions { display: flex; gap: 8px; }

.icon-btn {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
  cursor: pointer;
  font-size: 14px;
  font-weight: 600;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all var(--transition);
}

.icon-btn:hover { background: var(--primary-light); border-color: var(--primary); }

/* Main */
#app-main {
  max-width: 1100px;
  margin: 24px auto;
  padding: 0 20px;
}

.card {
  background: var(--surface);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 24px;
  margin-bottom: 20px;
  border: 1px solid var(--border);
  transition: background var(--transition), border-color var(--transition);
}

.card h2 { font-size: 22px; margin-bottom: 8px; color: var(--text); }
.card h3 { font-size: 16px; margin: 16px 0 12px; color: var(--text); }
.subtitle { color: var(--text-secondary); font-size: 14px; margin-bottom: 20px; }

/* Mode panels */
.mode-panel { display: none; }
.mode-panel.active { display: block; animation: fadeIn 0.25s ease; }

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

/* Stats bar */
.stats-bar {
  display: flex;
  gap: 24px;
  margin-bottom: 20px;
  flex-wrap: wrap;
}

.stat-item { text-align: center; }
.stat-label { display: block; font-size: 11px; text-transform: uppercase; letter-spacing: 0.5px; color: var(--text-secondary); font-weight: 600; }
.stat-value { display: block; font-size: 28px; font-weight: 700; color: var(--primary); }
.stat-value.countdown { color: var(--error); }

/* Text display */
.text-display {
  font-family: 'Courier New', Courier, monospace;
  font-size: 20px;
  line-height: 1.8;
  padding: 20px;
  background: var(--bg);
  border-radius: var(--radius);
  border: 1px solid var(--border);
  margin-bottom: 16px;
  min-height: 100px;
  user-select: none;
  overflow-wrap: break-word;
}

.char { transition: color 0.05s; }
.char.current { border-bottom: 2px solid var(--primary); }
.char.correct { color: var(--success); }
.char.incorrect { color: var(--error); background: rgba(222,53,11,0.1); border-radius: 2px; }
.char.pending { color: var(--text-secondary); }

/* Typing input */
.typing-input {
  width: 100%;
  padding: 12px 16px;
  font-size: 18px;
  font-family: 'Courier New', Courier, monospace;
  border: 2px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
  color: var(--text);
  outline: none;
  transition: border-color var(--transition);
}

.typing-input:focus { border-color: var(--primary); box-shadow: 0 0 0 2px var(--primary-light); }

/* Buttons */
.btn {
  padding: 8px 20px;
  font-size: 14px;
  font-weight: 600;
  border: none;
  border-radius: var(--radius);
  cursor: pointer;
  transition: all var(--transition);
}

.btn-primary { background: var(--primary); color: #fff; }
.btn-primary:hover { background: var(--primary-hover); }
.btn-secondary { background: var(--bg); color: var(--text); border: 1px solid var(--border); }
.btn-secondary:hover { background: var(--primary-light); }
.btn-lg { padding: 14px 36px; font-size: 16px; }

.action-bar { display: flex; gap: 12px; align-items: center; flex-wrap: wrap; margin-top: 16px; }

select {
  padding: 8px 12px;
  border-radius: var(--radius);
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
  font-size: 14px;
  cursor: pointer;
}

/* Virtual Keyboard */
#keyboard-container { overflow-x: auto; }

#virtual-keyboard {
  display: flex;
  flex-direction: column;
  gap: 6px;
  align-items: center;
  min-width: 600px;
}

.kb-row { display: flex; gap: 4px; }

.kb-key {
  min-width: 42px;
  height: 42px;
  border-radius: 6px;
  border: 1px solid var(--border);
  background: var(--bg);
  color: var(--text);
  font-size: 12px;
  font-weight: 600;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.1s;
  text-transform: uppercase;
}

.kb-key.highlight {
  background: var(--primary);
  color: #fff;
  border-color: var(--primary);
  box-shadow: 0 0 8px rgba(0,82,204,0.4);
  transform: scale(1.08);
}

.kb-key.pressed {
  background: var(--success);
  color: #fff;
  border-color: var(--success);
}

.kb-key.wide { min-width: 70px; }
.kb-key.wider { min-width: 90px; }
.kb-key.space { min-width: 260px; }

/* Lesson grid */
.lesson-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
  gap: 12px;
}

.lesson-card {
  padding: 16px;
  border-radius: var(--radius);
  border: 1px solid var(--border);
  background: var(--bg);
  cursor: pointer;
  transition: all var(--transition);
  position: relative;
}

.lesson-card:hover { border-color: var(--primary); box-shadow: var(--shadow); }
.lesson-card.completed { border-left: 4px solid var(--success); }
.lesson-card .lesson-num { font-size: 11px; color: var(--text-secondary); text-transform: uppercase; letter-spacing: 0.5px; }
.lesson-card .lesson-name { font-weight: 600; font-size: 14px; margin-top: 4px; }
.lesson-card .lesson-keys { font-size: 12px; color: var(--text-secondary); margin-top: 4px; font-family: monospace; }
.lesson-card .lesson-check { position: absolute; top: 12px; right: 12px; color: var(--success); font-size: 18px; }

/* Challenge */
.challenge-options { display: flex; gap: 12px; margin-bottom: 20px; justify-content: center; }
.challenge-time-btn.active { background: var(--primary); color: #fff; }

/* Modal */
.modal {
  position: fixed;
  inset: 0;
  background: rgba(9,30,66,0.54);
  z-index: 200;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
}

.modal-content {
  max-width: 560px;
  width: 100%;
  max-height: 90vh;
  overflow-y: auto;
  animation: modalIn 0.2s ease;
}

@keyframes modalIn { from { opacity: 0; transform: scale(0.95); } to { opacity: 1; transform: scale(1); } }

.results-grid {
  display: flex;
  justify-content: center;
  gap: 48px;
  margin: 24px 0;
}

.result-big { text-align: center; }
.result-big .big-num { display: block; font-size: 48px; font-weight: 800; color: var(--primary); }
.result-big span:last-child { font-size: 13px; color: var(--text-secondary); text-transform: uppercase; }

.results-details { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; margin-bottom: 16px; font-size: 14px; color: var(--text-secondary); }
.results-actions { justify-content: center; margin-top: 20px; }

.weak-keys-list { display: flex; gap: 8px; flex-wrap: wrap; margin-bottom: 12px; }
.weak-key-tag {
  display: inline-block;
  padding: 4px 12px;
  border-radius: 20px;
  background: rgba(222,53,11,0.1);
  color: var(--error);
  font-weight: 600;
  font-size: 13px;
  font-family: monospace;
}

/* FAQ */
.faq-container {
  max-width: 1100px;
  margin: 0 auto 40px;
  padding: 0 20px;
}

.faq-item { border-bottom: 1px solid var(--border); }
.faq-item summary {
  padding: 16px 0;
  font-weight: 600;
  font-size: 15px;
  cursor: pointer;
  color: var(--text);
  list-style: none;
}
.faq-item summary::before { content: '+'; margin-right: 12px; color: var(--primary); font-size: 18px; font-weight: 700; }
.faq-item[open] summary::before { content: '\2212'; }
.faq-item p { padding: 0 0 16px 28px; font-size: 14px; color: var(--text-secondary); line-height: 1.7; }

/* Footer */
#app-footer {
  text-align: center;
  padding: 24px;
  color: var(--text-secondary);
  font-size: 13px;
  border-top: 1px solid var(--border);
}

/* Canvas */
canvas { width: 100%; height: auto; border-radius: var(--radius); }

/* Responsive */
@media (max-width: 768px) {
  .header-inner { flex-wrap: wrap; height: auto; padding: 10px 16px; }
  #main-nav { order: 3; width: 100%; justify-content: flex-start; overflow-x: auto; padding-bottom: 4px; }
  .nav-btn { padding: 6px 12px; font-size: 13px; }
  .stats-bar { gap: 16px; }
  .stat-value { font-size: 22px; }
  .text-display { font-size: 16px; padding: 14px; }
  .typing-input { font-size: 16px; }
  .results-grid { gap: 24px; }
  .result-big .big-num { font-size: 36px; }
  .lesson-grid { grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); }
  .kb-key { min-width: 30px; height: 34px; font-size: 10px; }
  .kb-key.space { min-width: 160px; }
}

@media (max-width: 480px) {
  .card { padding: 16px; }
  .stats-bar { gap: 12px; justify-content: space-around; }
  .text-display { font-size: 15px; }
}
