:root {
  --bg-a: #ecf8ff;
  --bg-b: #f6fff3;
  --panel: #ffffff;
  --text: #1c2b33;
  --accent: #0e7b7b;
  --accent-2: #f7b733;
  --ok: #2b9348;
  --warn: #b23a48;
  --border: #d3e1ea;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  background: radial-gradient(circle at 10% 0%, var(--bg-a), transparent 35%),
              radial-gradient(circle at 90% 20%, var(--bg-b), transparent 40%),
              #f5f9fc;
  color: var(--text);
}

.wrap {
  max-width: 1040px;
  margin: 0 auto;
  padding: 20px 14px 34px;
}

.panel {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 16px;
  margin-bottom: 16px;
  box-shadow: 0 10px 22px rgba(31, 61, 89, 0.08);
}

h1 {
  margin: 0 0 10px;
  font-size: 30px;
}

p {
  font-size: 16px;
  margin: 6px 0;
  line-height: 1.6;
}

.controls {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
  align-items: center;
  margin-top: 12px;
}

.pane-head {
  display: flex;
  justify-content: flex-end;
  align-items: center;
  margin-bottom: 8px;
}

.countdown-host {
  position: relative;
}

.countdown-overlay {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  font-size: clamp(52px, 12vw, 110px);
  font-weight: bold;
  color: #0d5f5f;
  letter-spacing: 0.08em;
  text-shadow: 0 2px 0 #ffffff, 0 10px 24px rgba(13, 95, 95, 0.22);
  background: rgba(240, 252, 255, 0.62);
  backdrop-filter: blur(1px);
  border-radius: 12px;
  pointer-events: none;
  z-index: 20;
}

.countdown-overlay.is-finish {
  font-size: clamp(44px, 9vw, 88px);
  letter-spacing: 0.12em;
  background: rgba(236, 250, 243, 0.68);
  color: #0a6b49;
}

.score-overlay {
  position: fixed;
  inset: 0;
  display: grid;
  place-items: center;
  background: rgba(18, 33, 43, 0.46);
  backdrop-filter: blur(2px);
  z-index: 40;
}

.score-overlay[hidden] {
  display: none;
}

.score-dialog {
  width: min(560px, calc(100vw - 28px));
  background: #ffffff;
  border: 1px solid #c9dceb;
  border-radius: 16px;
  box-shadow: 0 20px 42px rgba(20, 44, 61, 0.2);
  padding: 18px;
}

.score-title {
  margin: 0 0 12px;
  color: #11354a;
  font-size: 28px;
}

.score-body {
  display: grid;
  gap: 10px;
}

.score-summary {
  border: 1px solid #d5e6d9;
  border-radius: 12px;
  background: linear-gradient(135deg, #f5fff8, #f3fbff);
  padding: 14px;
}

.score-total {
  font-size: 40px;
  font-weight: bold;
  color: #0a6b49;
  line-height: 1;
}

.score-caption {
  margin-top: 6px;
  color: #35576c;
  font-size: 15px;
}

.score-rank {
  margin-top: 8px;
  display: inline-block;
  padding: 4px 10px;
  border-radius: 999px;
  border: 1px solid #9fd3b3;
  background: #effdf4;
  color: #0a6b49;
  font-size: 14px;
  font-weight: bold;
}

.score-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 10px;
}

.score-card {
  border: 1px solid #d4e2eb;
  border-radius: 10px;
  background: #f8fcff;
  padding: 12px;
}

.score-card-label {
  color: #476375;
  font-size: 14px;
}

.score-card-value {
  margin-top: 4px;
  color: #17384c;
  font-size: 24px;
  font-weight: bold;
}

.score-note {
  color: #4e6676;
  font-size: 14px;
  line-height: 1.6;
}

.score-actions {
  display: flex;
  justify-content: flex-end;
  margin-top: 14px;
}

input {
  padding: 11px 12px;
  border-radius: 8px;
  border: 1px solid var(--border);
  font-size: 16px;
  min-width: 240px;
  background: #f7fbff;
}

button {
  border: none;
  border-radius: 10px;
  padding: 12px 16px;
  font-size: 18px;
  font-weight: bold;
  color: #fff;
  background: linear-gradient(120deg, #0f8a8a, #0d7070);
  cursor: pointer;
  box-shadow: 0 6px 14px rgba(14, 123, 123, 0.25);
}

button:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

.status {
  font-size: 20px;
  font-weight: bold;
  margin-bottom: 8px;
}

.phase {
  display: inline-block;
  margin-bottom: 8px;
  padding: 5px 10px;
  border-radius: 999px;
  background: #eef8ff;
  border: 1px solid #cfe7f7;
  font-size: 14px;
  font-weight: bold;
}

#arena {
  position: relative;
  width: 100%;
  height: 460px;
  border-radius: 12px;
  border: 2px dashed #9ac2db;
  background: repeating-linear-gradient(
    45deg,
    #f7fcff,
    #f7fcff 12px,
    #eef7fc 12px,
    #eef7fc 24px
  );
  overflow: hidden;
  user-select: none;
}

#target {
  position: absolute;
  border: none;
  border-radius: 999px;
  background: radial-gradient(circle at 30% 30%, #ffe9a8 0%, #ffc44f 55%, #f19011 100%);
  box-shadow: 0 6px 12px rgba(0, 0, 0, 0.2);
  display: none;
}

.click-target {
  position: absolute;
  border: none;
  border-radius: 999px;
  background: radial-gradient(circle at 30% 30%, #ffe9a8 0%, #ffc44f 55%, #f19011 100%);
  box-shadow: 0 6px 12px rgba(0, 0, 0, 0.2);
  display: none;
}

.result {
  margin-top: 8px;
  font-size: 16px;
  color: var(--warn);
  min-height: 24px;
}

.metrics {
  display: grid;
  grid-template-columns: repeat(3, minmax(140px, 1fr));
  gap: 8px;
  margin-top: 10px;
}

/* キーボード練習は 正解・不正解・正確さ・1キーあたり の4つを1列に並べる */
#paneKeyboard .metrics {
  grid-template-columns: repeat(4, minmax(120px, 1fr));
}

@media (max-width: 900px) {
  #paneKeyboard .metrics { grid-template-columns: repeat(2, minmax(120px, 1fr)); }
}

.metric {
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 10px;
  background: #f5fcff;
  font-size: 16px;
}

.meter {
  margin-top: 10px;
  height: 14px;
  border-radius: 999px;
  background: #e9f0f5;
  overflow: hidden;
  border: 1px solid #d2dee8;
}

.meter > div {
  height: 100%;
  width: 0;
  background: linear-gradient(120deg, #2b9348, #6ecb63);
  transition: width 0.25s ease;
}

.help {
  background: #fffdf3;
  border: 1px solid #f3e6b8;
  border-radius: 10px;
  padding: 10px;
  font-size: 16px;
  line-height: 1.6;
  margin-top: 10px;
}

.cat-tabs {
  display: flex;
  gap: 10px;
  margin-top: 12px;
}

.cat-btn {
  flex: 1;
  border: 2px solid #cfe1ea;
  border-radius: 12px;
  padding: 13px 16px;
  background: #f7fbff;
  color: #15323f;
  font-size: 18px;
  font-weight: bold;
  cursor: pointer;
  text-align: center;
  box-shadow: none;
}

.cat-btn.active {
  border-color: #0d7e7e;
  background: #e8f8f8;
  color: #0d5f5f;
}

.sub-menu {
  display: flex;
  gap: 8px;
  margin-top: 8px;
  flex-wrap: wrap;
  justify-content: center;
  align-items: center;
}

.sub-menu .mode-btn {
  width: min(220px, 100%);
  min-height: 50px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}

#comprehensiveSubMenu .mode-btn {
  width: min(240px, 100%);
}

.mode-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(160px, 1fr));
  gap: 10px;
  margin-top: 12px;
  margin-bottom: 0;
}

.mode-btn {
  border: 2px solid #cfe1ea;
  border-radius: 10px;
  padding: 10px 14px;
  background: #f7fbff;
  color: #15323f;
  font-size: 16px;
  font-weight: bold;
  cursor: pointer;
  text-align: center;
  box-shadow: none;
}

.mode-btn.active {
  border-color: #0d7e7e;
  background: #e8f8f8;
  color: #0d5f5f;
}

.exercise-pane {
  display: none;
  border-top: 2px solid var(--border);
  margin-top: 14px;
  padding-top: 14px;
}

.exercise-pane.active {
  display: block;
}

.mini-arena {
  border: 2px dashed #9ac2db;
  border-radius: 12px;
  min-height: 220px;
  background: #f8fcff;
  display: grid;
  place-items: center;
  padding: 12px;
}

.mini-arena.free {
  position: relative;
  min-height: 270px;
  overflow: hidden;
  display: block;
}

.icon-box {
  width: 96px;
  height: 96px;
  border-radius: 14px;
  display: grid;
  place-items: center;
  font-size: 42px;
  background: linear-gradient(135deg, #ffd880, #ffb347);
  border: 2px solid #ec9d25;
  cursor: pointer;
  user-select: none;
  position: absolute;
}

.drag-item {
  width: 90px;
  height: 90px;
  border-radius: 12px;
  background: linear-gradient(135deg, #9ad1ff, #55a3ff);
  border: 2px solid #2f7ed5;
  display: grid;
  place-items: center;
  color: #fff;
  font-size: 34px;
  font-weight: bold;
  cursor: grab;
}

.drag-source-wrap {
  position: absolute;
  width: 90px;
  height: 90px;
}

.drop-zone {
  position: absolute;
  width: 170px;
  min-height: 120px;
  border: 3px dashed #7ec08b;
  border-radius: 12px;
  background: #f1fff3;
  display: grid;
  place-items: center;
  font-size: 18px;
  font-weight: bold;
  color: #2b7c3d;
}

.typing-area {
  border: 2px solid #cde0ef;
  border-radius: 12px;
  background: #f8fcff;
  padding: 14px;
}

.typing-levels {
  display: grid;
  grid-template-columns: repeat(4, minmax(130px, 1fr));
  gap: 8px;
  margin-bottom: 10px;
}

.level-btn {
  border: 2px solid #bfd5e3;
  border-radius: 10px;
  background: #f5fbff;
  color: #204257;
  font-size: 15px;
  font-weight: bold;
  padding: 9px 10px;
  cursor: pointer;
  box-shadow: none;
}

.level-btn.active {
  border-color: #1c7f7f;
  background: #e3f6f6;
}

.typing-label {
  margin: 4px 0;
  color: #3b5466;
  font-size: 15px;
  font-weight: bold;
}

.typing-vertical {
  border: 1px solid #d1e3f0;
  border-radius: 10px;
  background: #fff;
  max-width: 760px;
  margin: 0 auto 10px;
  margin-bottom: 10px;
  overflow: hidden;
}

.typing-line {
  padding: 10px;
  border-bottom: 1px solid #e3eef6;
}

.typing-line:last-child {
  border-bottom: none;
}

.typing-line-value {
  margin: 0;
  color: #16364b;
  font-size: 22px;
  font-weight: bold;
  letter-spacing: 0.03em;
  text-align: center;
}

.typing-input {
  width: 100%;
  min-width: 0;
  font-size: 22px;
  padding: 12px 14px;
  border: 2px solid #9ec4de;
  background: #fff;
}

.typing-input:focus {
  outline: 2px solid #8dc8f0;
  outline-offset: 1px;
}

.typing-input.is-error {
  border-color: #d15b5b;
  background: #fff5f5;
}

.typing-help {
  margin-top: 8px;
  margin-bottom: 8px;
  color: #1d4f71;
  font-size: 16px;
  font-weight: bold;
}

.typing-guide {
  border: 1px solid #c9dceb;
  border-radius: 10px;
  background: #f1f9ff;
  padding: 10px;
}

.keyboard-visual {
  display: grid;
  gap: 8px;
  justify-items: center;
  width: 100%;
  margin: 0 auto;
}

.keyboard-row {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 6px;
}

.kbd-key {
  border: 2px solid #94b4c9;
  border-radius: 8px;
  background: #ffffff;
  color: #1f3b4e;
  font-size: 17px;
  font-weight: bold;
  line-height: 1;
  height: 46px;
  min-width: 44px;
  padding: 0 10px;
  display: grid;
  place-items: center;
}

.kbd-key.wide {
  min-width: 86px;
}

.kbd-key.space {
  min-width: 280px;
  max-width: 380px;
  flex: 0 0 auto;
}

/* ---- 指ごとの色: 左手は赤〜緑、右手は青緑〜ピンク、親指は茶と灰。
   キーと指の絵を同じ色にして、どの指で押すか見てわかるようにする。 */
[data-finger="left-pinky"]   { --finger: #d9363e; --finger-soft: #ffe2d9; --finger-ink: #fff; }
[data-finger="left-ring"]    { --finger: #e8590c; --finger-soft: #ffe6d1; --finger-ink: #fff; }
[data-finger="left-middle"]  { --finger: #e0a800; --finger-soft: #fff3c2; --finger-ink: #3b2f00; }
[data-finger="left-index"]   { --finger: #2f9e44; --finger-soft: #d8f5dc; --finger-ink: #fff; }
[data-finger="left-thumb"]   { --finger: #8d6e63; --finger-soft: #efe5df; --finger-ink: #fff; }
[data-finger="right-thumb"]  { --finger: #6c757d; --finger-soft: #e9ecef; --finger-ink: #fff; }
[data-finger="right-index"]  { --finger: #0c8599; --finger-soft: #cdf3f8; --finger-ink: #fff; }
[data-finger="right-middle"] { --finger: #1c6fd6; --finger-soft: #d6e8ff; --finger-ink: #fff; }
[data-finger="right-ring"]   { --finger: #7048e8; --finger-soft: #e6ddff; --finger-ink: #fff; }
[data-finger="right-pinky"]  { --finger: #d6338a; --finger-soft: #ffe0f2; --finger-ink: #fff; }

.kbd-key[data-finger]:not([data-finger=""]) {
  background: var(--finger-soft);
  border-color: color-mix(in srgb, var(--finger) 45%, #ffffff);
}

/* Shift を押している間は、記号だけを表示する（記号のないキーは空） */
.kbd-shift-label { display: none; }
.keyboard-visual.is-shift .kbd-label { display: none; }
.keyboard-visual.is-shift .kbd-shift-label { display: inline; }
.keyboard-visual.is-shift .kbd-key[data-key^="shift"] {
  box-shadow: inset 0 3px 0 rgba(0, 0, 0, 0.18);
  transform: translateY(2px);
}

.kbd-key.active {
  border-color: #21805f;
  background: #e8ffef;
  color: #1f6b4f;
}

.kbd-key.active[data-finger]:not([data-finger=""]) {
  background: var(--finger);
  border-color: var(--finger);
  color: var(--finger-ink);
  box-shadow: 0 0 0 3px #ffffff, 0 0 0 6px var(--finger);
  transform: translateY(-2px);
}

.hands-visual {
  margin-top: 10px;
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
}

.hand-card {
  border: 1px solid #c7d9e6;
  border-radius: 12px;
  background: #f7fafc;
  padding: 10px;
}

.hand-card p {
  margin: 0 0 6px;
  font-size: 14px;
  font-weight: bold;
  color: #2d4f66;
}

.hand-shape {
  position: relative;
  width: min(340px, 100%);
  height: 180px;
  margin: 0 auto;
}

.finger {
  position: absolute;
  border: 2px solid #8d99a6;
  border-radius: 28px 28px 0 0;
  background: #cfd6de;
  color: transparent;
  font-size: 0;
  width: 56px;
  height: 122px;
  display: grid;
  place-items: center;
}

.finger[data-finger] {
  background: var(--finger-soft);
  border-color: color-mix(in srgb, var(--finger) 55%, #ffffff);
  /* 色だけに頼らないよう、指の名前（小・薬・中・人・親）も表示する */
  color: var(--finger);
  font-size: 20px;
  font-weight: bold;
  place-items: start center;
  padding-top: 12px;
}

.hand-shape.left .finger-top.pinky { left: 8px; top: 32px; }
.hand-shape.left .finger-top.ring { left: 76px; top: 24px; }
.hand-shape.left .finger-top.middle { left: 144px; top: 16px; }
.hand-shape.left .finger-top.index { left: 212px; top: 24px; }

.hand-shape.right .finger-top.index { left: 8px; top: 24px; }
.hand-shape.right .finger-top.middle { left: 76px; top: 16px; }
.hand-shape.right .finger-top.ring { left: 144px; top: 24px; }
.hand-shape.right .finger-top.pinky { left: 212px; top: 32px; }

.palm {
  display: none;
}

.hand-shape.left .thumb {
  left: 176px;
  top: 90px;
  width: 70px;
  height: 124px;
  border-radius: 30px 30px 10px 10px;
  transform: rotate(25deg);
}

.hand-shape.right .thumb {
  left: 94px;
  top: 90px;
  width: 70px;
  height: 124px;
  border-radius: 30px 30px 10px 10px;
  transform: rotate(-25deg);
}

.finger.active {
  border-color: var(--finger, #005a9c);
  background: var(--finger, #8fc9ff);
  color: var(--finger-ink, #fff);
  box-shadow: 0 0 0 4px #ffffff, 0 0 0 7px var(--finger, #005a9c);
}

.score-good {
  color: var(--ok);
}

.score-warning {
  color: var(--warn);
}

@media (max-width: 840px) {
  .mode-grid { grid-template-columns: repeat(2, minmax(160px, 1fr)); }
}

@media (max-width: 680px) {
  h1 { font-size: 25px; }
  #arena { height: 400px; }
  .metrics { grid-template-columns: 1fr; }
  .mode-grid { grid-template-columns: 1fr; }
  .typing-levels { grid-template-columns: repeat(2, minmax(120px, 1fr)); }
  .typing-line-value { font-size: 18px; }
  .score-grid { grid-template-columns: 1fr; }
  .score-title { font-size: 24px; }
  .score-total { font-size: 34px; }
  .sub-menu .mode-btn {
    width: 100%;
  }
  .kbd-key {
    font-size: 15px;
    min-width: 36px;
    height: 40px;
    padding: 0 8px;
  }
  .kbd-key.wide { min-width: 70px; }
  .kbd-key.space { min-width: 220px; }
  .hands-visual { grid-template-columns: 1fr; }
  .hand-shape {
    width: min(300px, 100%);
    height: 166px;
  }
  .finger {
    width: 48px;
    height: 108px;
  }
  .hand-shape.left .finger-top.pinky { left: 6px; top: 34px; }
  .hand-shape.left .finger-top.ring { left: 64px; top: 26px; }
  .hand-shape.left .finger-top.middle { left: 122px; top: 18px; }
  .hand-shape.left .finger-top.index { left: 180px; top: 26px; }
  .hand-shape.right .finger-top.index { left: 6px; top: 26px; }
  .hand-shape.right .finger-top.middle { left: 64px; top: 18px; }
  .hand-shape.right .finger-top.ring { left: 122px; top: 26px; }
  .hand-shape.right .finger-top.pinky { left: 180px; top: 34px; }
  .hand-shape.left .thumb {
    left: 150px;
    top: 86px;
    width: 62px;
    height: 112px;
  }
  .hand-shape.right .thumb {
    left: 86px;
    top: 86px;
    width: 62px;
    height: 112px;
  }
  .typing-input { font-size: 20px; }
}

/* ---- KPM の目安（終了すると自分の段階が強調される） */
.kpm-scale-wrap { margin-top: 12px; }
.kpm-scale { display: grid; grid-template-columns: repeat(5, minmax(0, 1fr)); gap: 6px; }
.kpm-level {
  border: 2px solid #d5dfeb;
  border-radius: 10px;
  background: #f7fafc;
  padding: 8px;
  text-align: center;
  color: #5d6f80;
}
.kpm-level-name { font-weight: bold; font-size: 16px; color: #1f3b4e; }
.kpm-level-desc { font-size: 12px; line-height: 1.4; margin-top: 2px; }
.kpm-level.is-active {
  border-color: #1f7a4d;
  background: #e8f7ee;
  box-shadow: 0 0 0 3px #ffffff, 0 0 0 5px #1f7a4d;
}
.kpm-level.is-active .kpm-level-name { color: #1f7a4d; }
.kpm-level.is-active .kpm-level-name::before { content: "▶ "; }
@media (max-width: 900px) {
  .kpm-scale { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}
