:root {
  --bg: #14161c;
  --panel: #1d2027;
  --panel-2: #252a33;
  --text: #e7e9ee;
  --muted: #8b93a3;
  --accent: #4cc2ff;
  --green: #5fd68a;
  --red: #ff6b6b;
  --center: #b48cff;
  --daku: #ffb84c;
  --handaku: #ff8cc0;
  --small: #6be8d8;
}

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

#fx-canvas {
  position: fixed;
  inset: 0;
  pointer-events: none;
  z-index: 100;
}

body {
  background: var(--bg);
  color: var(--text);
  font-family: "Yu Gothic UI", "Meiryo", "Hiragino Sans", sans-serif;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

header { text-align: center; padding: 24px 16px 8px; position: relative; }
.sound-btn {
  position: absolute;
  top: 14px;
  right: 18px;
  font-size: 18px;
  padding: 6px 10px;
}
h1 { font-size: 26px; letter-spacing: 2px; }
.subtitle { color: var(--muted); font-size: 13px; margin-top: 4px; }
h2 { font-size: 17px; margin: 18px 0 10px; }

.view { display: none; max-width: 980px; width: 100%; margin: 0 auto; padding: 8px 20px 32px; }
.view.active { display: block; }

footer { text-align: center; color: var(--muted); font-size: 12px; padding: 12px; margin-top: auto; }
footer a { color: var(--accent); }

kbd {
  background: var(--panel-2);
  border: 1px solid #3a4150;
  border-radius: 4px;
  padding: 1px 5px;
  font-size: 12px;
}

/* --- IME 警告 --- */
#ime-warning {
  display: none;
  align-items: center;
  justify-content: center;
  gap: 12px;
  background: #5a3a1a;
  color: #ffd9a0;
  padding: 8px 16px;
  font-size: 14px;
}
#ime-warning.show { display: flex; }
#ime-warning .close {
  background: none; border: none; color: inherit; font-size: 18px; cursor: pointer;
}

/* --- メニュー --- */
.usage {
  background: var(--panel);
  border-radius: 10px;
  padding: 14px 18px;
  font-size: 14px;
}
.usage ul { margin: 6px 0 0 20px; line-height: 1.9; }
.usage h2 { margin-top: 0; }

#lesson-list {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
  gap: 10px;
}
.lesson-card {
  background: var(--panel);
  border: 1px solid #2c323e;
  border-radius: 10px;
  padding: 12px 14px;
  text-align: left;
  color: var(--text);
  cursor: pointer;
  display: flex;
  flex-direction: column;
  gap: 5px;
  transition: border-color .15s, transform .15s;
}
.lesson-card:hover { border-color: var(--accent); transform: translateY(-2px); }
.lesson-title { font-size: 15px; font-weight: bold; }
.lesson-desc { font-size: 12px; color: var(--muted); line-height: 1.5; }
.lesson-best { font-size: 12px; color: var(--green); }

.custom textarea {
  width: 100%;
  background: var(--panel);
  color: var(--text);
  border: 1px solid #2c323e;
  border-radius: 8px;
  padding: 10px;
  font-size: 15px;
  margin: 6px 0 10px;
  resize: vertical;
}
.custom p { font-size: 13px; color: var(--muted); }

.btn {
  background: var(--panel-2);
  color: var(--text);
  border: 1px solid #3a4150;
  border-radius: 8px;
  padding: 8px 16px;
  font-size: 14px;
  cursor: pointer;
}
.btn:hover { border-color: var(--accent); }
.btn.primary { background: #1b4965; border-color: var(--accent); }

/* --- レベル・XP --- */
.level-bar {
  display: flex;
  align-items: center;
  gap: 10px;
  background: var(--panel);
  border-radius: 10px;
  padding: 10px 14px;
  margin-bottom: 14px;
}
.level-badge {
  font-weight: bold;
  font-size: 16px;
  color: var(--daku);
  min-width: 52px;
}
.xp-track {
  flex: 1;
  height: 10px;
  background: var(--panel-2);
  border-radius: 5px;
  overflow: hidden;
}
.xp-fill {
  height: 100%;
  width: 0;
  background: linear-gradient(90deg, var(--accent), var(--center));
  border-radius: 5px;
  transition: width .6s ease;
}
.xp-text { font-size: 12px; color: var(--muted); min-width: 90px; text-align: right; }
.xp-gain { font-size: 14px; color: var(--green); font-weight: bold; }
.result-level { max-width: 560px; margin: 8px auto; }

/* --- 入力モード --- */
.mode {
  background: var(--panel);
  border-radius: 10px;
  padding: 12px 16px;
  margin-bottom: 4px;
}
.mode h2 { margin-top: 0; }
.mode-option {
  display: flex;
  gap: 8px;
  align-items: baseline;
  font-size: 14px;
  padding: 4px 0;
  cursor: pointer;
}
.mode-option span { line-height: 1.6; }
#emu-options {
  margin-top: 8px;
  font-size: 13px;
  color: var(--muted);
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}
#emu-options input[type="range"] { width: 140px; accent-color: var(--accent); }
#emu-window-val { color: var(--text); font-weight: bold; }

.mode-badge {
  background: var(--panel-2);
  border: 1px solid #3a4150;
  border-radius: 10px;
  padding: 2px 10px;
  font-size: 12px;
  color: var(--accent);
}

.emu-key {
  display: inline-block;
  background: var(--panel-2);
  border: 1px solid var(--accent);
  border-radius: 6px;
  padding: 2px 12px;
  margin: 0 2px;
  font-weight: bold;
  color: #fff;
}
.emu-plus { color: var(--muted); margin: 0 2px; }
.emu-note { color: var(--muted); font-size: 14px; margin-left: 10px; }

/* --- お題ファイル取り込み --- */
.import p, .custom p { font-size: 13px; color: var(--muted); margin-bottom: 6px; }
.import code {
  background: var(--panel-2);
  border-radius: 4px;
  padding: 1px 5px;
  font-size: 12px;
}
#dropzone {
  border: 2px dashed #3a4150;
  border-radius: 10px;
  padding: 22px;
  text-align: center;
  color: var(--muted);
  font-size: 14px;
  transition: border-color .15s, background .15s;
}
#dropzone.drag { border-color: var(--accent); background: #1b2530; color: var(--text); }
.filebtn {
  color: var(--accent);
  cursor: pointer;
  text-decoration: underline;
}
#import-msg { font-size: 13px; color: var(--green); min-height: 18px; margin-top: 6px; }
#import-msg.error { color: var(--red); }
.imported-wrap { position: relative; }
.imported-wrap .lesson-card { width: 100%; }
.imported-del {
  position: absolute;
  top: 6px;
  right: 8px;
  background: none;
  border: none;
  color: var(--muted);
  font-size: 16px;
  cursor: pointer;
}
.imported-del:hover { color: var(--red); }
#imported-list {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
  gap: 10px;
}

/* --- 練習画面 --- */
.practice-bar {
  display: flex;
  align-items: center;
  gap: 16px;
  margin-bottom: 10px;
}
#practice-title { font-weight: bold; }
#practice-progress { color: var(--muted); }
.practice-bar .btn:last-child { margin-left: auto; }

.stats { display: flex; gap: 10px; margin-bottom: 18px; }
.stat {
  background: var(--panel);
  border-radius: 8px;
  padding: 6px 14px;
  display: flex;
  flex-direction: column;
  align-items: center;
  min-width: 86px;
}
.stat .label { font-size: 11px; color: var(--muted); }
.stat span:last-child { font-size: 18px; font-weight: bold; }
.stat.big { padding: 14px 22px; }
.stat.big span:last-child { font-size: 28px; color: var(--accent); }

.stat.combo span:last-child { color: var(--daku); }
.stat.combo.hot span:last-child {
  color: var(--red);
  animation: combo-pulse .5s ease infinite alternate;
}
@keyframes combo-pulse {
  to { transform: scale(1.25); text-shadow: 0 0 10px var(--red); }
}
.stat.score span:last-child { color: var(--accent); }

#target-wrap { position: relative; }
#fx-layer {
  position: absolute;
  inset: 0;
  pointer-events: none;
  overflow: visible;
}
.fx-pop {
  position: absolute;
  top: 10%;
  font-weight: bold;
  font-size: 22px;
  color: var(--green);
  animation: fx-float .9s ease-out forwards;
  text-shadow: 0 2px 8px rgba(0, 0, 0, .6);
}
.fx-pop.fx-combo { color: var(--daku); font-size: 28px; }
.fx-pop.fx-perfect {
  color: #ffd700;
  font-size: 30px;
  text-shadow: 0 0 14px rgba(255, 215, 0, .7);
}
@keyframes fx-float {
  0% { transform: translateY(0); opacity: 0; }
  15% { opacity: 1; }
  100% { transform: translateY(-56px); opacity: 0; }
}

#target-text {
  text-align: center;
  font-size: 44px;
  letter-spacing: 6px;
  min-height: 70px;
  margin-bottom: 4px;
}
#target-text .done { color: var(--green); }
#target-text .current {
  color: var(--accent);
  border-bottom: 3px solid var(--accent);
}
#target-text.miss-flash { animation: shake .18s linear; }
@keyframes shake {
  25% { transform: translateX(-5px); }
  75% { transform: translateX(5px); }
}

#romaji-hint {
  text-align: center;
  font-family: Consolas, monospace;
  font-size: 20px;
  letter-spacing: 2px;
  min-height: 30px;
  margin-bottom: 16px;
  overflow-wrap: anywhere;
}
#romaji-hint .typed { color: var(--green); }
#romaji-hint .rest { color: var(--muted); }

/* --- キーボードガイド --- */
#keyboard {
  display: flex;
  justify-content: center;
  gap: 46px;
  margin-bottom: 12px;
}
.kb-half { display: flex; flex-direction: column; gap: 6px; }
.kb-row { display: flex; gap: 6px; }
.kb-left .kb-row { justify-content: flex-end; }
.kb-right .kb-row { justify-content: flex-start; }

.kb-key {
  width: 58px;
  height: 58px;
  background: var(--panel);
  border: 1px solid #2c323e;
  border-radius: 8px;
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background .1s, border-color .1s, box-shadow .1s;
}
.kb-main { font-size: 20px; }
.kb-sub {
  position: absolute;
  top: 4px;
  right: 6px;
  font-size: 11px;
  color: var(--center);
}
.kb-qwerty {
  position: absolute;
  bottom: 3px;
  left: 6px;
  font-size: 9px;
  color: var(--muted);
  font-family: Consolas, monospace;
}
.kb-fn .kb-main { color: var(--muted); font-size: 15px; }

.kb-space-row { justify-content: center !important; }
.kb-left .kb-space-row { justify-content: flex-end !important; }
.kb-right .kb-space-row { justify-content: flex-start !important; }
.kb-space { width: 122px; height: 40px; }
.kb-space .kb-main { font-size: 13px; color: var(--center); }

/* シフト能力キーの目印(下辺の色) */
.shift-center { border-bottom: 3px solid var(--center); }
.shift-daku { border-bottom: 3px solid var(--daku); }
.shift-handaku { border-bottom: 3px solid var(--handaku); }
.shift-small { border-bottom: 3px solid var(--small); }

.kb-key.hit {
  background: #1b4965;
  border-color: var(--accent);
  box-shadow: 0 0 12px rgba(76, 194, 255, .45);
}
.kb-key.hit .kb-main { color: #fff; }

.legend {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 14px;
  font-size: 12px;
  color: var(--muted);
}
.legend .sw {
  display: inline-block;
  width: 14px;
  height: 10px;
  border-radius: 3px;
  margin-right: 4px;
  background: var(--panel-2);
}
.legend .shift-center { border-bottom: 3px solid var(--center); }
.legend .shift-daku { border-bottom: 3px solid var(--daku); }
.legend .shift-handaku { border-bottom: 3px solid var(--handaku); }
.legend .shift-small { border-bottom: 3px solid var(--small); }
.legend .hit-sample {
  background: #1b4965;
  border: 1px solid var(--accent);
  box-shadow: 0 0 6px rgba(76, 194, 255, .45);
}

/* --- 結果画面 --- */
#view-result { text-align: center; }
.rank {
  font-size: 84px;
  font-weight: bold;
  line-height: 1.1;
  animation: rank-in .5s cubic-bezier(.2, 1.6, .4, 1);
}
@keyframes rank-in {
  0% { transform: scale(3); opacity: 0; }
  100% { transform: scale(1); opacity: 1; }
}
.rank-s { color: #ffd700; text-shadow: 0 0 24px rgba(255, 215, 0, .55); }
.rank-a { color: var(--accent); text-shadow: 0 0 18px rgba(76, 194, 255, .5); }
.rank-b { color: var(--green); }
.rank-c { color: var(--center); }
.rank-d { color: var(--muted); }
.stars { letter-spacing: 2px; }
.stars span { color: #4a505e; font-size: inherit; }
.stars .on { color: #ffd700; }
#result-stars { font-size: 30px; margin: 4px 0 6px; }
.lesson-title .stars { font-size: 12px; margin-left: 4px; }
#result-levelup { color: var(--daku); font-size: 18px; min-height: 24px; }
#result-perfect {
  color: #ffd700;
  font-size: 24px;
  font-weight: bold;
  min-height: 30px;
  text-shadow: 0 0 16px rgba(255, 215, 0, .6);
  animation: rank-in .6s cubic-bezier(.2, 1.6, .4, 1);
}
.result-grid {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 14px;
  margin: 18px 0;
}
#result-best { color: var(--daku); font-size: 18px; min-height: 26px; }
.result-actions { display: flex; justify-content: center; gap: 12px; margin-top: 10px; }

@media (max-width: 760px) {
  #keyboard { gap: 18px; }
  .kb-key { width: 44px; height: 44px; }
  .kb-main { font-size: 16px; }
  #target-text { font-size: 32px; }
}
